I am Fetching CustomerId using

  public function getCurrentCustomerId()

        return $this->_customerSession->getCustomerId();


But After cache is enabled no id is returned (This was a known issue and was said to solved in Magento 2.1 but still facing the issue)


In 2.1, I'm pretty sure you can use Magento\Customer\Helper\Session\CurrentCustomer to retrieve the current customer when cache is enabled.

Indeed, this class provides a method called getCustomer that seems to behave differently whether or not the cache is enabled:

public function getCustomer()
    if ($this->moduleManager->isEnabled('Magento_PageCache')
        && !$this->request->isAjax()
        && $this->view->isLayoutLoaded()
        && $this->layout->isCacheable()
    ) {
        return $this->getDepersonalizedCustomer();
    } else {
        return $this->getCustomerFromService();
  • I tried "$this->_currentCustomer->getCustomer()->getId();" Still the problem persists – Vishwas Bhatnagar Sep 1 '16 at 14:39
  • @VishwasBhatnagar hmm that's weird. What if you call getCustomerId ? – Raphael at Digital Pianism Sep 1 '16 at 14:40
  • No luck with this as well , as soon as i turn on cache using 'bin/magento cache:enable' , there is no id. i am using EE , 2.1 was supposed to solve all these issues :( – Vishwas Bhatnagar Sep 1 '16 at 14:44
  • @VishwasBhatnagar you're using EE ? Well I don't have access to an EE instance unfortunately I guess my knowledge stops here – Raphael at Digital Pianism Sep 1 '16 at 14:47
  • CE and EE have the same code base i guess , at-least these core functionality . Thanks for looking into issue you are always very helpful and active – Vishwas Bhatnagar Sep 1 '16 at 14:54

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.