首页 > 解决方案 > 在主页中获取客户 ID - Magento 2

问题描述

我需要在主页中获取主要的客户 ID,但没有会话接口来提供此信息。

我试过论文:

\Magento\Backend\Model\Session
\Magento\Catalog\Model\Session
\Magento\Checkout\Model\Session
\Magento\Customer\Model\Session
\Magento\Newsletter\Model\Session

是否存在一个界面以在每一页上提供客户 ID ?

标签: phpmagentomagento2

解决方案


There are methods available in magento2 to get customer id, one of the method is using Object Manager as below code.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();  
$customerSession = $objectManager->get('Magento\Customer\Model\Session');  
$customerId = $customerSession->getCustomer()->getId(); // get the customer Id

推荐阅读