Hello, Magento Buddies!

As we all know that the default Magento offers one Magento website, store, and store views. Thereafter, multiple websites, stores, and their store views can be built depending on the requirements.

So, to fetch a list of all the stores, you are required to perform only a few pieces of code which are right hereinafter. The method is pretty easy. Also, to know how you can quickly set up multiple stores in Magento 2, where I have given a step-by-step guide to configuring multiple stores in Magento 2.

Let’s Commence!

Steps To Retrieve a List Of All Stores Programmatically

Step 1: Create a Store.php file in the below path.

app\code\Vendor\Extension\Block\

Now, add the below-given code:

Step 2: Next, add the below code in your phtml file:

And, it’s done!

Wrap Up!

Integrate the above code appropriately and you will surely get the desired output to get a list of all the Magento 2 stores.

Grab the Magento Multi-Store & Website Setup Service and get ready with multiple stores and websites from a single admin panel. 

Happy Coding!

Click to rate this post!
[Total: 8 Average: 5]