【发布时间】:2011-02-12 08:55:22
【问题描述】:
在 Magento 中,我如何获取活跃的商店信息,例如商店名称、行号等?
【问题讨论】:
在 Magento 中,我如何获取活跃的商店信息,例如商店名称、行号等?
【问题讨论】:
获取商店数据
Mage::app()->getStore();
商店 ID
Mage::app()->getStore()->getStoreId();
商店代码
Mage::app()->getStore()->getCode();
网站 ID
Mage::app()->getStore()->getWebsiteId();
商店名称
Mage::app()->getStore()->getName();
商店前端名称(请参阅@Ben 的回答)
Mage::app()->getStore()->getFrontendName();
有效
Mage::app()->getStore()->getIsActive();
商店首页网址
Mage::app()->getStore()->getHomeUrl();
商店的当前页面 URL
Mage::app()->getStore()->getCurrentUrl();
所有这些函数都可以在类Mage_Core_Model_Store
中找到文件:app/code/core/Mage/Core/Model/Store.php
【讨论】:
Mage::app()->getStore() 的费用是多少?我假设商店是第一个被实例化的全局变量之一,所以这可能非常便宜。是吗?
要从 Magento 的任何地方获取有关当前商店的信息,请使用:
<?php
$store = Mage::app()->getStore();
这将为您提供一个 Mage_Core_Model_Store 对象,其中包含您需要的一些信息:
<?php
$name = $store->getName();
至于您关于行号的其他问题,我不确定您的意思。如果您的意思是您想知道代码中的行号(例如用于错误处理),请尝试:
<?php
$line = __LINE__;
$file = __FILE__;
$class = __CLASS__;
$method = __METHOD__;
$namespace = __NAMESPACE__;
【讨论】:
Mage::app()->getWebsite()->getStores(); ,但它只返回当前商店。
这里有很好的答案。如果您正在寻找 Magento 配置中设置的默认视图“商店名称”:
Mage::app()->getStore()->getFrontendName()
【讨论】:
仅供参考,关于我的需要......我在这里寻找的答案是:
Mage::app()->getStore()->getGroup()->getName()
这是在管理页面上引用的,一个可以管理多个商店... admin/system_store,我想检索商店组标题...
【讨论】:
在 Magento 1.9.4.0 以及 1.x 中的所有版本都使用:
Mage::getStoreConfig('general/store_information/address');
还有以下参数,看你想得到什么:
【讨论】:
如果您在前端工作,请使用:
$currentStore=Mage::app()->getStore();
如果您有商店 ID,请使用
$store=Mage::getmodel('core/store')->load($storeId);
【讨论】:
Magento 商店 ID:Mage::app()->getStore()->getStoreId();
Magento 商店名称:Mage::app()->getStore()->getName();
【讨论】:
您可以像这样获取活跃的商店信息:
Mage::app()->getStore(); // for store object
Mage::app()->getStore()->getStoreId; // for store ID
【讨论】: