How to get store information in Magento?
Asked Answered
T

9

74

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

Theda answered 26/4, 2010 at 11:32 Comment(0)
H
90

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__;
Hannan answered 26/4, 2010 at 13:42 Comment(2)
How do you get all the active store codes? I tryed Mage::app()->getWebsite()->getStores(); but it only returns the current store.Ial
I have display Notes in PDP page like, Delivery : 5 to 10 days, how can I change Delivery : 10 to 30 days based on current store. Here i have 2 stores.Reichert
A
153

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

Alunite answered 30/3, 2011 at 5:16 Comment(6)
how we can get the main store name from adminhtml.while i m using Mage::app()->getStore()->getName() using this i m getting 'admin'.Radiotelephony
@gowri, the admin area counts as a separate store (with id 0), if you have an order or anything to work with you can do, for example: $storeId = $order->getStoreId(); $store = Mage::getModel('core/store')->load($storeId); $name = $store->getWebsite()->getName();Growth
How expensive is a call to Mage::app()->getStore()? I assume that the store is one of the first globals to be instantiated anyway so this would probably be very cheap. Yes?Quarry
When I call Mage::app()->getStore()->getName(); it returns "English" Magento 1.9.2.3 using the demo store data.Surcingle
I have display Notes in PDP page like, Delivery : 5 to 10 days, how can I change Delivery : 10 to 30 days based on current store. Here i have 2 stores.Reichert
working correctlyVarlet
H
90

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__;
Hannan answered 26/4, 2010 at 13:42 Comment(2)
How do you get all the active store codes? I tryed Mage::app()->getWebsite()->getStores(); but it only returns the current store.Ial
I have display Notes in PDP page like, Delivery : 5 to 10 days, how can I change Delivery : 10 to 30 days based on current store. Here i have 2 stores.Reichert
S
29

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

Mage::app()->getStore()->getFrontendName()
Seften answered 16/2, 2013 at 20:5 Comment(1)
This should be the accepted answer. When I call Mage::app()->getStore()->getName(); it returns "English" Magento 1.9.2.3 using the demo store data.Surcingle
S
9

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

Scarabaeus answered 30/9, 2013 at 8:59 Comment(0)
N
4

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

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
Nickelodeon answered 11/1, 2019 at 7:45 Comment(0)
L
1

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);
Loup answered 25/5, 2018 at 6:38 Comment(0)
B
0

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

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

Brassica answered 18/10, 2019 at 5:28 Comment(0)
P
0

For Magento 1:

you can use all of these functions can be found in class Mage_Core_Model_Store

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

Store Data

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

Store Id

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

Store code

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

Magento 2 Using Block

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

Using Object Manager

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        
 
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
 
echo $storeManager->getStore()->getStoreId();

That's it

Prau answered 9/10, 2022 at 14:58 Comment(0)
W
-1

You can get active store information like this:

Mage::app()->getStore();  // for store object
Mage::app()->getStore()->getStoreId;  // for store ID
Watercolor answered 29/5, 2018 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.