如何在Magento获取商店信息?

时间:2010-04-26 11:32:43

标签: php magento

在Magento,我如何获得有效的商店信息,如商店名称,行号等?

8 个答案:

答案 0 :(得分:150)

获取商店数据

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();

商店的当前页面网址

Mage::app()->getStore()->getCurrentUrl();
  

所有这些功能都可以在课程 Mage_Core_Model_Store

中找到      

文件: app / code / core / Mage / Core / Model / Store.php

答案 1 :(得分:85)

要从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__;

答案 2 :(得分:28)

这里很棒的答案。如果您正在寻找Magento配置中设置的默认视图“Store Name”:

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

答案 3 :(得分:9)

仅仅为了提供信息,关于我的需要......我在这里寻找的答案是:

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

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

答案 4 :(得分:1)

如果您正在使用Frontend那么使用:

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

如果您有商店ID,请使用

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

答案 5 :(得分:1)

在Magento 1.9.4.0中,也许1.x中的所有版本都使用:

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

和以下参数,这取决于您想要获得什么:

  • 常规/商店信息/名称
  • 常规/ store_information /电话
  • general / store_information / merchant_country
  • 常规/ store_information /地址
  • 一般/ store_information / merchant_vat_number

答案 6 :(得分:0)

Magento商店ID Mage::app()->getStore()->getStoreId();

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

答案 7 :(得分:-1)

您可以获得这样的有效商店信息:

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