In Magento, how can I get active store information, like store name, line number, etc?
You can get store ID by calling the block function in your phtml file. echo $block->getStoreId(); Using Object Manager.
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();
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!
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
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__;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With