Skip to content
NewRedesigned blogFeedback
Jigar Karangiya

Magento 2: How to get all stores list programmatically

Magento provides StoreRepositoryInterface to fetch all store lists and store-related information : Magento\Store\Api\StoreRepositoryInterface

Magento 2: How to get all stores list programmatically
Written by
JKJigar Karangiya
Published
Reading time
1 min read

Jigar Karangiya · · 1 min read

Hello Devs,

In today’s Quick tutorial, we will see how to get all stores lists programmatically in Magento 2.

Default Magento provides one Magento website (opens in new tab), store (opens in new tab), and store views (opens in new tab).

This information is usually stored in the “store ” table of your Magento 2 database.

Magento provides StoreRepositoryInterface to fetch all store lists and store-related information :
Magento\Store\Api\StoreRepositoryInterface

Using this repository we can fetch store-related information like store_id, code, website_id, group_id, name, sort_order,**** and**** is_active.

See example below :

php
<?php
namespace Jigar\Tutorials\Block;
 
use \Magento\Store\Api\StoreRepositoryInterface;
 
class Example
{
    /**
     * @var \Magento\Store\Api\StoreRepositoryInterface
     */
    protected $storeRepository;
    
    /**
     * @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
     */
    public function __construct(
        \Magento\Store\Api\StoreRepositoryInterface $storeRepository
    ) {
        $this->storeRepository = $storeRepository;
    }
    /**
     * {@inheritdoc}
     */
    public function getAllStoresList()
    {
        $stores = [];
        foreach ($this->storeRepository->getList() as $store) {
                $stores[] = $store->getData();
        }
        return $stores;
    }
    /**
     * {@inheritdoc}
     */
    public function getAllActiveStoresList()
    {
        $stores = [];
        foreach ($this->storeRepository->getList() as $store) {
            if ($store->isActive()) {
                $stores[] = $store->getData();
            }
        }
        return $stores;
    }
}

In the above example, We can see we have created 2 functions,

  1. getAllStoresList() – Will return all stores lists – with store-related information
  2. getAllActiveStoresList() – will return all active store list

Sample Output :

javascript
[
    [
      "store_id" => "0",
      "code" => "admin",
      "website_id" => "0",
      "group_id" => "0",
      "name" => "Admin",
      "sort_order" => "0",
      "is_active" => "1",
    ],
    [
      "store_id" => "1",
      "code" => "default",
      "website_id" => "1",
      "group_id" => "1",
      "name" => "Default Store View",
      "sort_order" => "0",
      "is_active" => "1",
    ],
  ]

You can change the function logic as per your requirement.

That’s it for this tutorial, Do not missout to check below useful tutorials.

How to clear previous messages in MessageManager programmatically?

Add Yes/No Attribute in Magento 2 programmatically

Securely render Javascript inside Magento 2 template files using PHP

Thank You!!

Keep reading
All posts

01 · 10 min · Shares Adobe Commerce Core

Adobe Commerce Agentic Capabilities, Q4 2026

Five agentic releases for Adobe Commerce: LLM product discovery, Brand Visibility, the Shopper MCP server, Brand Concierge, and Experience Workspace. What each one does, which editions get it, and when.

10 min

03 · 3 min · Shares Adobe Commerce Core

Conditions for Collections in Magento 2

Collections in Magento 2 (Now Adobe Commerce), are among the most powerful tools for retrieving and manipulating data directly from the database.

3 min

Newsletter

New Magento tutorials, straight to your inbox

Code examples, performance tips, and fixes for common Magento issues. No spam.

Subscribe