Magento 2: Get Store Information (Store ID, Code, Name, URL, Website ID)

http://blog.chapagain.com.np/magento-2-get-store-information-store-id-code-name-url-website-id/

This article shows how we can get store information in Magento 2. We will be fetching store id, store code, store name, store url, and store’s website id. We also write a function which checks if the store is active or not.

Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object ofStoreManagerInterface in the constructor of my module’s block class.

app/code/Chapagain/HelloWorld/Block/HelloWorld.php

See more functions in vendor/magento/module-store/Model/Store.php.

Now, we print the store information in our template (.phtml) file.

Leave a Comment