Get customer session data with cache in block

Questions

QuestionsGet customer session data with cache in block
0 Answers
Qaisar Satti Staff answered 6 years ago

You can get session data in cache using obejct manager. So using following code you can get customer session data with cache enabled

namespace QaisarSatti\Module\Block;

class HelloWorld extends \Magento\Framework\View\Element\Template
{

  protected $objectmanager;  


  public function __construct(
     
        \Magento\Framework\ObjectManagerInterface $objectmanager

    ) {


        $this->objectmanager = $objectmanager;
     
    }
    public function getCustomerData()
    {
         $customerSession = $this->objectmanager->create('Magento\Customer\Model\SessionFactory')->create();
         return $customerSession;
    }

}