如何在 Magento 获取商店信息?

在 Magento,我如何得到活跃的商店信息,如商店名称,行号等?

157435 次浏览

要从 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()->getStore();

存储 ID

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

存储代码

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

网站名

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

店名

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

存储前端名称 (本的回答)

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

已激活

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

店铺网址

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

商店的当前页面 URL

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

所有这些函数都可以在类 核心模型存储中找到

档案: App/code/Core/Mage/Core/Model/Store.php

如果你正在寻找 Magento 配置中设置的默认视图“ Store Name”:

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

只是为了信息的缘故,关于我的需要... 我在这里寻找的答案是:

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

这是在管理页面上引用的,其中一个可以管理多个存储... admin/system _ store,我想检索存储组标题..。

如果你正在使用 Fronend,那么使用:

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

如果您有存储 ID,则使用

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

你可以像这样获得活跃的商店信息:

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

在 Magento 1.9.4.0或者1.x 的所有版本中都会使用:

GetStoreConfig (‘ general/store _ information/address’) ;

下面的参数,取决于你想得到什么:

  • General/store _ information/name
  • 一般/商店/信息/电话
  • 一般资料/商店资料/商人国家
  • 一般/store _ information/address
  • 一般/商店 _ 信息/商人 _ 增值税 _ 号码

Magento Store Id : Mage::app()->getStore()->getStoreId();

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

Magento 1:

你可以在类 Mage_Core_Model_Store中找到所有这些函数

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

存储数据

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

存储 ID

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

就是这样