【问题标题】:How to get store information in Magento?如何在 Magento 中获取商店信息?
【发布时间】:2011-02-12 08:55:22
【问题描述】:

在 Magento 中,我如何获取活跃的商店信息,例如商店名称、行号等?

【问题讨论】:

    标签: php magento


    【解决方案1】:

    获取商店数据

    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

    【讨论】:

    • 我们如何从 adminhtml 获取主商店名称。而我正在使用 Mage::app()->getStore()->getName() 使用这个我得到 '管理员”。
    • @gowri,管理区域算作一个单独的商店(id 为 0),如果您有订单或任何需要处理的事情,例如:$storeId = $order->getStoreId (); $store = Mage::getModel('core/store')->load($storeId); $name = $store->getWebsite()->getName();
    • 拨打Mage::app()->getStore() 的费用是多少?我假设商店是第一个被实例化的全局变量之一,所以这可能非常便宜。是吗?
    • 当我调用 Mage::app()->getStore()->getName();它使用演示商店数据返回“英语”Magento 1.9.2.3。
    • 我在 PDP 页面中显示了备注,例如,交货时间:5 到 10 天,我如何根据当前商店更改交货时间:10 到 30 天。这里我有 2 家商店。
    【解决方案2】:

    要从 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()-&gt;getWebsite()-&gt;getStores(); ,但它只返回当前商店。
    • 我在 PDP 页面中显示了备注,例如,交货时间:5 到 10 天,我如何根据当前商店更改交货时间:10 到 30 天。这里我有 2 家商店。
    【解决方案3】:

    这里有很好的答案。如果您正在寻找 Magento 配置中设置的默认视图“商店名称”:

    Mage::app()->getStore()->getFrontendName()
    

    【讨论】:

    • 这应该是公认的答案。当我调用 Mage::app()->getStore()->getName();它使用演示商店数据返回“英语”Magento 1.9.2.3。
    【解决方案4】:

    仅供参考,关于我的需要......我在这里寻找的答案是:

    Mage::app()->getStore()->getGroup()->getName()
    

    这是在管理页面上引用的,一个可以管理多个商店... admin/system_store,我想检索商店组标题...

    【讨论】:

      【解决方案5】:

      在 Magento 1.9.4.0 以及 1.x 中的所有版本都使用:

      Mage::getStoreConfig('general/store_information/address');

      还有以下参数,看你想得到什么:

      • 一般/store_information/name
      • 一般/store_information/电话
      • general/store_information/merchant_country
      • general/store_information/address
      • general/store_information/merchant_vat_number

      【讨论】:

        【解决方案6】:

        如果您在前端工作,请使用:

        $currentStore=Mage::app()->getStore(); 
        

        如果您有商店 ID,请使用

        $store=Mage::getmodel('core/store')->load($storeId);
        

        【讨论】:

          【解决方案7】:

          Magento 商店 IDMage::app()-&gt;getStore()-&gt;getStoreId();

          Magento 商店名称Mage::app()-&gt;getStore()-&gt;getName();

          【讨论】:

            【解决方案8】:

            您可以像这样获取活跃的商店信息:

            Mage::app()->getStore();  // for store object
            Mage::app()->getStore()->getStoreId;  // for store ID
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2012-06-29
              • 2013-07-13
              • 2012-07-17
              相关资源
              最近更新 更多