magepow / customersession
Help you able to get customer session data when varnish cache is enable.
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Type:magento2-module
Requires
- magepow/core: ^1.0.0
README
Magento 2 CustomerSession Extension Free
In Magento 2, we can't get customer session from \Magento\Customer\Model\Session when varnish cache is enable so we use \Magento\Framework\App\Http\Context instead. But by default, \Magento\Framework\App\Http\Context only gives the value of customer_group and customer_logged_in. CustomerSession extension free by Magepow allows you to get more than just customer_group and customer_logged_in is customer id, name, email and other customer attributes if set.
How to install Magento 2 CustomerSession extension Free
✓ Install Magepow CustomerSession via composer (recommend)
Run the following command in Magento 2 root folder:
composer require magepow/customersession
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
Magepow CustomerSession user guide
Example:
1. Get customer_logged_in
$ObjectManager= \Magento\Framework\App\ObjectManager::getInstance();
$context = $ObjectManager->get('Magento\Framework\App\Http\Context');
$isLoggedIn = $context->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
1. Get customer_group
$ObjectManager= \Magento\Framework\App\ObjectManager::getInstance();
$context = $ObjectManager->get('Magento\Framework\App\Http\Context');
$isLoggedIn = $context->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP);
1. Get customer id
$ObjectManager= \Magento\Framework\App\ObjectManager::getInstance();
$context = $ObjectManager->get('Magento\Framework\App\Http\Context');
$isLoggedIn = $context->getValue('customer_id');
1. Get customer name
$ObjectManager= \Magento\Framework\App\ObjectManager::getInstance();
$context = $ObjectManager->get('Magento\Framework\App\Http\Context');
$isLoggedIn = $context->getValue('customer_name');
1. Get customer email
$ObjectManager= \Magento\Framework\App\ObjectManager::getInstance();
$context = $ObjectManager->get('Magento\Framework\App\Http\Context');
$isLoggedIn = $context->getValue('customer_email');
To get more customer attributes you have to edit method aroundDispatch in \Magepow\CustomerSession\Plugin\CustomerSessionContext.php
Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)