{"id":72433,"date":"2017-01-21T17:38:33","date_gmt":"2017-01-21T17:38:33","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=72433"},"modified":"2017-01-21T17:38:33","modified_gmt":"2017-01-21T17:38:33","slug":"list-magento-stores-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/","title":{"rendered":"List All Magento Stores in Magento2"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Magento manages multiple Websites, Stores as well as there store views. After\u00a0installation by default one default Website, store and it&#8217;s store view created after that user\u00a0can create multi Websites, Stores and there store views as per as requirement.<\/p>\n<p>This article demonstrate how to fetch list of all Magento stores in Magento 2.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>In earlier version(1.9.*) of Magento below codes helps to fetch list of all Magento stores,<\/strong><\/p>\n<pre class=\"brush:php\">$stores = Mage::getModel('core\/store_api')-&gt;items();\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>As there have several things are changed in Magento 2. So below code will help to fetch list of all stores in Magento 2.<\/strong><\/p>\n<p><!--more--><\/p>\n<pre class=\"brush:php\">&lt;?php\r\n \r\nnamespace Webkul\\Demo\\Model;\r\n\r\nuse \\Magento\\Store\\Model\\StoreRepository;\r\n \r\nclass Stores extends \\Magento\\Framework\\DataObject \r\n    implements \\Magento\\Framework\\Option\\ArrayInterface\r\n{\r\n    \/**\r\n     * @var Rate\r\n     *\/\r\n    protected $_storeRepository;\r\n     \r\n    \/**\r\n     * @param StoreRepository      $storeRepository\r\n     *\/\r\n    public function __construct(\r\n        StoreRepository $storeRepository\r\n    ) {\r\n        $this-&gt;_storeRepository = $storeRepository;\r\n    }\r\n  \r\n    public function toOptionArray()\r\n    {\r\n        $stores = $this-&gt;_storeRepository-&gt;getList();\r\n        $websiteIds = array();\r\n        $storeList = array();\r\n        foreach ($stores as $store) {\r\n            $websiteId = $store[\"website_id\"];\r\n            $storeId = $store[\"store_id\"];\r\n            $storeName = $store[\"name\"];\r\n            $storeList[$storeId] = $storeName;\r\n            array_push($websiteIds, $websiteId);\r\n        }\r\n        return $storeList;\r\n    }\r\n}<\/pre>\n<ul>\n<li><strong>_storeRepository:<\/strong> Is an object of &#8220;Magento\\Store\\Model\\StoreRepository&#8221; class.<\/li>\n<li><strong>$store[&#8220;website_id&#8221;] :\u00a0<\/strong>It will return\u00a0website\u00a0id.<\/li>\n<li><strong>$store[&#8220;store_id&#8221;] :\u00a0<\/strong>It will return\u00a0store id.<\/li>\n<li><strong>$store[&#8220;name&#8221;] :\u00a0<\/strong>It will return\u00a0store name.<\/li>\n<li><strong>$store[&#8220;group_id&#8221;] :\u00a0<\/strong>It will return\u00a0store group id.<\/li>\n<li><strong>$store[&#8220;code&#8221;] :\u00a0<\/strong>It will return\u00a0store code which is unique as per as store.<\/li>\n<li><strong>toOptionArray() : <\/strong>This \u00a0method will return list of stores.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Magento manages multiple Websites, Stores as well as there store views. After\u00a0installation by default one default Website, store and it&#8217;s store view created after that user\u00a0can create multi Websites, Stores and there store views as per as requirement. This article demonstrate how to fetch list of all Magento stores in Magento 2. &nbsp; In <a href=\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":90,"featured_media":70261,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,302],"tags":[2460,4389,4388,2941],"class_list":["post-72433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento","category-magento2","tag-magento-2","tag-store-view","tag-stores","tag-website"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>List of All Magento Stores in Magento 2<\/title>\n<meta name=\"description\" content=\"Magento manages multiple Websites, Stores as well as there store views.This article demonstrate how to fetch list of all Magento stores in Magento 2.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"List of All Magento Stores in Magento 2\" \/>\n<meta property=\"og:description\" content=\"Magento manages multiple Websites, Stores as well as there store views.This article demonstrate how to fetch list of all Magento stores in Magento 2.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-21T17:38:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ashish Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashish Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/\"},\"author\":{\"name\":\"Ashish Singh\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/3b92c698256ce0bcb9613acf8bbf5b2d\"},\"headline\":\"List All Magento Stores in Magento2\",\"datePublished\":\"2017-01-21T17:38:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/\"},\"wordCount\":163,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png\",\"keywords\":[\"Magento 2\",\"Store View\",\"Stores\",\"website\"],\"articleSection\":[\"magento\",\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/\",\"name\":\"List of All Magento Stores in Magento 2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png\",\"datePublished\":\"2017-01-21T17:38:33+00:00\",\"description\":\"Magento manages multiple Websites, Stores as well as there store views.This article demonstrate how to fetch list of all Magento stores in Magento 2.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"List All Magento Stores in Magento2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/3b92c698256ce0bcb9613acf8bbf5b2d\",\"name\":\"Ashish Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ef2c82640f6054d8a8cfca9e3edd7edaf800ff1873b6d103c7bbf0b47dfefc1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ef2c82640f6054d8a8cfca9e3edd7edaf800ff1873b6d103c7bbf0b47dfefc1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Ashish Singh\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/ashish067\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"List of All Magento Stores in Magento 2","description":"Magento manages multiple Websites, Stores as well as there store views.This article demonstrate how to fetch list of all Magento stores in Magento 2.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/","og_locale":"en_US","og_type":"article","og_title":"List of All Magento Stores in Magento 2","og_description":"Magento manages multiple Websites, Stores as well as there store views.This article demonstrate how to fetch list of all Magento stores in Magento 2.","og_url":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2017-01-21T17:38:33+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png","type":"image\/png"}],"author":"Ashish Singh","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Ashish Singh","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/"},"author":{"name":"Ashish Singh","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/3b92c698256ce0bcb9613acf8bbf5b2d"},"headline":"List All Magento Stores in Magento2","datePublished":"2017-01-21T17:38:33+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/"},"wordCount":163,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png","keywords":["Magento 2","Store View","Stores","website"],"articleSection":["magento","Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/","url":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/","name":"List of All Magento Stores in Magento 2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png","datePublished":"2017-01-21T17:38:33+00:00","description":"Magento manages multiple Websites, Stores as well as there store views.This article demonstrate how to fetch list of all Magento stores in Magento 2.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/01\/Magneto-Code-Snippet.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/list-magento-stores-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"List All Magento Stores in Magento2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/3b92c698256ce0bcb9613acf8bbf5b2d","name":"Ashish Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ef2c82640f6054d8a8cfca9e3edd7edaf800ff1873b6d103c7bbf0b47dfefc1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ef2c82640f6054d8a8cfca9e3edd7edaf800ff1873b6d103c7bbf0b47dfefc1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Ashish Singh"},"url":"https:\/\/webkul.com\/blog\/author\/ashish067\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/72433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/90"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=72433"}],"version-history":[{"count":5,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/72433\/revisions"}],"predecessor-version":[{"id":72438,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/72433\/revisions\/72438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/70261"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=72433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=72433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=72433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}