magepow/customersession

Help you able to get customer session data when varnish cache is enable.

1.0.0 2021-07-21 08:54 UTC

This package is auto-updated.

Last update: 2024-10-30 01:32:03 UTC


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 :)

paypal

Our Magento 2 Extensions

Our Magento 2 services

Our Magento 2 Themes

Our Shopify Themes

Our Shopify App

Our WordPress Theme