Magento 2: How to get all websites list programmatically?

Magento 2-How to get all websites list programmatically

Hello Devs,

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

Default Magento provides one Magento websitestore, and store views.

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

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

Using this repository we can fetch website-related information like website_id, code, name, default_group_id, and is_default.

See example below :

As shown in the above example,

when we call the getAllWebsitesList() function, it will return all website lists with website-related information.

Sample Output :

You can change the function logic as per your requirement.

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

Magento 2: How to get all stores list programmatically

how to get shared catalog data by ID in Magento 2?

How to Get Store Configuration value in Magento 2?

Thank You!!

Leave a Reply

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