Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get store information in Magento?

Tags:

php

magento

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

like image 809
Chirag Avatar asked Apr 26 '10 11:04

Chirag


People also ask

How can I get current store ID in Magento 2?

You can get store ID by calling the block function in your phtml file. echo $block->getStoreId(); Using Object Manager.

How do I get store view in Magento 2?

You may need to get a current Store ID, Store Code, Name, Website ID, or current URL. You can use the object manager to quickly get the StoreManager object for a test, as in the example bellow: $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

How do you get a store code?

To get there, log into your GMB profile and click on the “Info” tab. Once you're in the Info tab, you'll see a section called “Advanced” information. There, you'll be able to see your store code and update it easily!


2 Answers

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

like image 190
Mukesh Chapagain Avatar answered Sep 19 '22 13:09

Mukesh Chapagain


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__; 
like image 36
Joe Mastey Avatar answered Sep 22 '22 13:09

Joe Mastey