Magento 2: How to get all stores list programmatically

Magento2 - How to get all stores list programmatically

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, store, and store views.

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 :

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 :

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 :

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!!

Leave a Reply

Your email address will not be published. Required fields are marked *