Getting a list of magento stores

Getting a list of magento stores

July 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Getting a list of magento stores

Getting a List of Magento Stores and Store Groups

As a senior developer working extensively with the Magento platform, I often need to retrieve lists of stores and store groups for various purposes such as data analysis, module configuration, or system administration tasks. In this post, we’ll explore how to efficiently achieve this using Magento’s built-in APIs.

Retrieving Store Groups Under a Website

To get a list of store groups within a specific website in Magento, you can use the Magento_Catalog module’s API. Here’s an example of fetching all store groups associated with a particular website:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeGroupRepository = $objectManager->create('Magento\Catalog\Model\ResourceModel\Group\Collection');

$storeGroups = $storeGroupRepository->addFieldToSelect('*')
    ->load()
    ->toArray();

foreach ($storeGroups as $group) {
    echo "Store Group ID: " . $group['entity_id'] . ", Name: " . $group['name'];
}

This code snippet uses Magento’s object manager to instantiate a Collection of store groups and adds all fields for selection. The load() method retrieves the data, which is then converted to an array using toArray(). We iterate through this array to print out each group’s ID and name.

Retrieving Stores from a Store Group

Once you have identified the desired store group, you can fetch the stores within that group using the Magento_Store module. Here’s how:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeRepository = $objectManager->create('Magento\Store\Model\ResourceModel\Group\Collection');

$storesInGroup = $storeRepository->addFieldToSelect('*')
    ->load()
    ->toArray();

foreach ($stores as $store) {
    echo "Store ID: " . $store['entity_id'] . ", Name: " . $store['name'];
}

The process is similar to the previous example, but this time we’re using Magento’s Group collection and selecting stores instead of store groups. You can replace 'Magento\Store\Model\ResourceModel\Group' with the actual group ID you want to fetch.

Best Practices and Recommendations

While the code provided here works directly within a Magento context, for production environments it’s recommended to use Magento’s built-in controller actions or service contracts instead of relying on the object manager. This approach ensures proper dependency injection and maintains a clean separation between your custom code and Magento’s core functionality.

For more advanced operations or if you’re working with Laravel Company, consider looking into their extension for seamless integration with Magento: Laravel Company’s Magento API Integration.

Conclusion

Retrieving store groups and stores in Magento is a fundamental task that every developer should be comfortable with. By leveraging the built-in collection classes and APIs, you can efficiently manage Magento’s multi-site architecture for various use cases.

Remember to always follow best practices for working with Magento’s object manager in development environments, and consider using dedicated service contracts or API controllers in production settings. If you’re looking to integrate your Laravel application with a Magento store, be sure to explore the solutions offered by Laravel Company.

Happy coding!

Catalog API Extensions Admin

Our network