3

Here I am unable to get customer session data ($customerSession) it's working in Magento version 2.2.3 but not working 2.2.4 it return false when cacheable is false.

namespace Namespace\ModuleName\Helper;


class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    public $customerSession;

    public function __construct(
        \Magento\Customer\Model\Session $customerSession
    ) {
        $this->customerSession = $customerSession;
        parent::__construct($context);
    }



    public function getCustomerGroup() {
        if($this->customerSession->isLoggedIn()) {
            $groups = $this->customerSession->getCustomer()->getGroupId();
            return $groups;
        }
        return '0';
    }

}
2

It version specific issue in Magento 2.2.4 you can check here,
Url :- https://github.com/magento/magento2/issues/3294

<?php


namespace CompanyName\ModuleName\Helper;


class Data extends \Magento\Framework\App\Helper\AbstractHelper
{

    /**
     * @var \Magento\Customer\Model\SessionFactory
     */
    private $sessionFactory;


    /**
     * Data constructor.
     * @param \Magento\Framework\App\Helper\Context $context
     * @param \Magento\Customer\Model\SessionFactory $sessionFactory
     */
    public function __construct(
        \Magento\Framework\App\Helper\Context $context,
        \Magento\Customer\Model\SessionFactory $sessionFactory
    ) {
        parent::__construct($context);
        $this->sessionFactory = $sessionFactory;
    }

    public function getCustomerId()
    {

       $customerId = $this->sessionFactory->create()->getCustomer()->getId();
       return $customerId;
    }


}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.