Php 在主页中获取客户ID-Magento 2
我需要在主页中获取主要客户ID,但没有会话界面来提供此信息 我试过这些论文:Php 在主页中获取客户ID-Magento 2,php,magento,magento2,Php,Magento,Magento2,我需要在主页中获取主要客户ID,但没有会话界面来提供此信息 我试过这些论文: \Magento\Backend\Model\Session \Magento\Catalog\Model\Session \Magento\Checkout\Model\Session \Magento\Customer\Model\Session \Magento\Newsletter\Model\Session 存在一个界面,用于在每个页面上提供客户ID,如下图所示 $objectManager = \Mage
\Magento\Backend\Model\Session
\Magento\Catalog\Model\Session
\Magento\Checkout\Model\Session
\Magento\Customer\Model\Session
\Magento\Newsletter\Model\Session
存在一个界面,用于在每个页面上提供客户ID,如下图所示
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerId = $customerSession->getCustomer()->getId(); // get the customer Id
名称空间供应商\模块\块 类窗体扩展\Magento\Framework\View\Element\Template
protected $customerSession;
/**
* Construct
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Customer\Model\Session $customerSession
* @param array $data
*/
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()
{
var_dump($this->customerSession->getCustomer()->getId());
exit();
return parent::_prepareLayout();
}