{"id":1800,"date":"2021-06-04T11:00:06","date_gmt":"2021-06-04T11:00:06","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-current-store-id-in-magento-2\/"},"modified":"2025-07-16T17:43:26","modified_gmt":"2025-07-16T12:13:26","slug":"get-current-store-id-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-current-store-id-in-magento-2\/","title":{"rendered":"How to Get Current Store ID in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">E-commerce has changed the way people do business and shop. With online shopping, a customer from France can make a purchase from a store in India! However, as the customer base increases, the store owners try to offer a shopping platform that is compatible with their shoppers\u2019 local language, currency, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hence,\u00a0Magento 2\u00a0allows having multi-stores to serve your customers with a shopping platform that is comfortable to them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to work with more than one store from a single administration, the store owner has to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/setup-magento-2-multi-store\/\" target=\"_blank\" rel=\"noreferrer noopener\">set up multi store in Magento 2<\/a>. While working with a multi-store environment, the need often arrives to&nbsp;get current store id in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Especially, when the store owner needs customization based on the store. For example, store A has different currency and product rates than store B.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before implementing any such condition-based customization, you first have to get the store ID, and then implement the logic such as if the store id is equal to one, then don\u2019t show a popup of discounted products or generate a store-specific CSV, otherwise do.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check out the below code to do so using block and object manager.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Related Post:&nbsp;<\/strong><a href=\"https:\/\/meetanshi.com\/blog\/get-website-id-and-store-id-from-admin-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Get Website ID and Store ID from Admin in Magento 2<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get Current Store ID in Magento 2<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Using Block<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">protected $storeManager;\n\npublic function __construct(\n    \\Magento\\Backend\\Block\\Template\\Context $context,\n    \\Magento\\Store\\Model\\StoreManagerInterface $storeManager,\n    array $data = []\n)\n{\n    $this->storeManager = $storeManager;\n    parent::__construct($context, $data);\n}\n\npublic function getStoreId()\n{\n    return $this->storeManager->getStore()->getId();\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can get store ID by calling the block function in your phtml file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo $block->getStoreId();<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Using Object Manager<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$objectManager =  \\Magento\\Framework\\App\\ObjectManager::getInstance();        \n \n$storeManager = $objectManager->get('\\Magento\\Store\\Model\\StoreManagerInterface');\n \necho $storeManager->getStore()->getStoreId();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I would be happy to answer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do consider sharing this post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>E-commerce has changed the way people do business and shop. With online shopping, a customer from France can make a purchase from a store in&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1800","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1800"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1800\/revisions"}],"predecessor-version":[{"id":18055,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1800\/revisions\/18055"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}