在 Magento 中,我如何获取活跃的商店信息,例如商店名称、行号等?
原文由 Chirag 发布,翻译遵循 CC BY-SA 4.0 许可协议
在 Magento 中,我如何获取活跃的商店信息,例如商店名称、行号等?
原文由 Chirag 发布,翻译遵循 CC BY-SA 4.0 许可协议
对于 Magento 1:
你可以使用所有这些功能可以在类中找到 Mage_Core_Model_Store
文件:app/code/core/Mage/Core/Model/Store.php
存储数据
Mage::app()->getStore();
商店编号
Mage::app()->getStore()->getStoreId();
商店代码
Mage::app()->getStore()->getCode();
Magento 2 使用块
protected $storeManager;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
array $data = []
)
{
$this->storeManager = $storeManager;
parent::__construct($context, $data);
}
public function getStoreId()
{
return $this->storeManager->getStore()->getId();
}
使用对象管理器
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
echo $storeManager->getStore()->getStoreId();
而已
原文由 Jyotishina Rajwani 发布,翻译遵循 CC BY-SA 4.0 许可协议
2 回答2.5k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
1 回答1.6k 阅读✓ 已解决
1 回答842 阅读✓ 已解决
2 回答492 阅读✓ 已解决
928 阅读
1 回答675 阅读
要从 Magento 的任何地方获取有关当前商店的信息,请使用:
这将为您提供一个 Mage_Core_Model_Store 对象,其中包含您需要的一些信息:
至于您关于行号的其他问题,我不确定您的意思。如果您的意思是您想知道代码中的行号(例如,用于错误处理),请尝试: