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();
}
}
.png)