How to Get Current Customer ID using customer session in Magento2 - magento source24

 

How to Get Current Customer ID using customer session in Magento2 - magento source24

How to Get Current Customer ID using customer session in Magento2 - magento source24


In this blog post im share code with you to How to Get Current Customer ID using customer session

👉 In this method i'm using customer Session using Class Magento\Customer\Model\Session 



namespace Vendor_Name\Module_Name\Block;

class Form extends \Magento\Framework\View\Element\Template

{

    protected $customerSession;


    public function __construct(

        \Magento\Framework\View\Element\Template\Context $context,

        \Magento\Customer\Model\Session $customerSession,

        array $data = []

    ) {

        parent::__construct($context, $data);

        $this->customerSession = $customerSession;

    }


    public function _prepareLayout()

    {

        print_r($this->customerSession->getCustomer()->getId());

        return parent::_prepareLayout();

    }

}






 

Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

Post a Comment

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post