How To Get Default Store ID in Magento 2
In Magento 2, it is possible creating a website with multiple stores having different designs, products, purposes, etc. Store view is nothing but, a variation of the same store with different attributes.
For example, in the case of different geographical regions, the attributes such as product title and description have to be translated into different languages. Thus, the store owner needs to create multiple store views with multiple languages.
However, every Magento 2 store has a default store view. The store owner may require to get the default store ID in Magento 2 programmatically for various purposes. For example, if you want to show the default Magento store view in a drop-down menu to the customers, you may require to retrieve the default store view of that particular Magento website.
You can refer to the solution provided here to get the default store ID in Magento 2.
Method to Get the Default Store ID in Magento 2
public function __construct(StoreManagerInterface $storeManager)
$this->storeManager = $storeManager;
// get default store id of website 1
$storeId = $this->storeManager->getWebsite($websiteId)->getDefaultStore()->getId();
If you have any questions regarding this post, feel free to ask in the comments section below
I’d be happy to answer.
Do consider sharing this post with the Magento community via social media.