How to get store information in Magento?

前端 未结 8 1694
你的背包
你的背包 2020-12-12 10:36

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

相关标签:
8条回答
  • 2020-12-12 11:16

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

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

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

    <?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__;
    
    0 讨论(0)
  • 2020-12-12 11:17

    Get store data

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

    Store Id

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

    Store code

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

    Website Id

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

    Store Name

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

    Store Frontend Name (see @Ben's answer)

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

    Is Active

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

    Homepage URL of Store

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

    Current page URL of Store

    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

    0 讨论(0)
  • 2020-12-12 11:17

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

    Mage::app()->getStore()->getFrontendName()
    
    0 讨论(0)
  • 2020-12-12 11:18

    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...

    0 讨论(0)
  • 2020-12-12 11:31

    If You are working on Frontend Then Use:

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

    If You have store id then use

    $store=Mage::getmodel('core/store')->load($storeId);
    
    0 讨论(0)
  • 2020-12-12 11:35

    You can get active store information like this:

    Mage::app()->getStore();  // for store object
    Mage::app()->getStore()->getStoreId;  // for store ID
    
    0 讨论(0)
提交回复
热议问题