php - 在主页中获取客户 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 ?
解决方案
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
推荐阅读
- mysql - 用于计算从开仓开始的当前余额的 SQL 查询
- ios - 更新 Xcode 11 和 IOS 13 后 Tabbar 按钮插入错误
- c++ - std::cout 不适用于结构的重载 '<<' 运算符
- sonarqube - 无法在 Windows 10 上安装 SonarQube v7.9.1
- c# - 使用 for 循环在列表框中打印值,但其中一些显示为字符串
- azure - Azure AD - 使用 offline_access 范围获取声明(ADAL 库)
- google-cloud-platform - 使用 gcloud 命令创建 Jupyter 笔记本
- java - 在多请求进来时保持java套接字存活
- byte - Pyserial 读取字节从串口返回垃圾值
- twilio - 如何使用 twilio 向任何电话号码发送消息?