php 如何在Magento中获取商店信息?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2713042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:27:05  来源:igfitidea点击:

How to get store information in Magento?

phpmagento

提问by Chirag

In Magento, how can I get active store information, like store name, line number, etc?

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

回答by Mukesh Chapagain

Get store data

获取店铺数据

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

Store Id

商店编号

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

Store code

商店代码

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

Website Id

网站 ID

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

Store Name

店铺名称

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

Store Frontend Name(see @Ben's answer)

商店前端名称见@Ben 的回答

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

Is Active

活跃

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

Homepage URL of Store

店铺主页 URL

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

Current page URL of Store

商店当前页面 URL

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

All of these functions can be found in class Mage_Core_Model_Store

File: app/code/core/Mage/Core/Model/Store.php

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

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

回答by Joseph Mastey

To get information about the current store from anywhere in Magento, use:

要从 Magento 的任何地方获取有关当前商店的信息,请使用:

<?php
$store = Mage::app()->getStore();

This will give you a Mage_Core_Model_Store object, which has some of the information you need:

这将为您提供一个 Mage_Core_Model_Store 对象,其中包含您需要的一些信息:

<?php
$name = $store->getName();


As for your other question about line number, I'm not sure what you mean. If you mean that you want to know what line number in the code you are on (for error handling, for instance), try:

至于您关于行号的其他问题,我不确定您的意思。如果您的意思是想知道您所在代码的行号(例如,用于错误处理),请尝试:

<?php
$line      = __LINE__;
$file      = __FILE__;
$class     = __CLASS__;
$method    = __METHOD__;
$namespace = __NAMESPACE__;

回答by Ben

Great answers here. If you're looking for the default view "Store Name" set in the Magento configuration:

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

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

回答by MediaVince

Just for information sake, in regards to my need... The answer I was looking for here was:

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

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

That is referenced on the admin page, where one can manage multiple stores... admin/system_store, I wanted to retrieve the store group title...

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

回答by István D?brentei

In Magento 1.9.4.0 and maybe all versions in 1.x use:

在 Magento 1.9.4.0 和 1.x 中的所有版本中可能使用:

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

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

and the following params, it depends what you want to get:

和以下参数,这取决于你想得到什么:

  • general/store_information/name
  • general/store_information/phone
  • general/store_information/merchant_country
  • general/store_information/address
  • general/store_information/merchant_vat_number
  • 一般/商店信息/名称
  • 一般/商店信息/电话
  • 一般/商店信息/商户国家/地区
  • 一般/商店信息/地址
  • 一般/store_information/merchant_vat_number

回答by Amar

If You are working on Frontend Then Use:

如果您正在使用前端,请使用:

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

If You have store id then use

如果您有商店 ID,则使用

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

回答by Milan Maniya

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

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

Magento Store Name: Mage::app()->getStore()->getName();

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

回答by Sudheer Pal

You can get active store information like this:

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

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