Skip to content
NewRedesigned blogFeedback
Jigar Karangiya

Magento 2: How to get all websites list programmatically?

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

Magento 2: How to get all websites 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 websites 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_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 :

php
<?php
namespace Jigar\Tutorials\Block;
use Magento\Store\Api\WebsiteRepositoryInterface;
 
/**
 * Class for get all websites list.
 */
class Example
{
    /**
     * @var WebsiteRepositoryInterface
     */
    private $websiteRepository;
    
    /**
     * @param WebsiteRepositoryInterface $websiteRepository
     */
    public function __construct(
        WebsiteRepositoryInterface $websiteRepository
    ) {
        $this->websiteRepository = $websiteRepository;
    }
    /**
     * {@inheritdoc}
     */
    public function getAllWebsitesList()
    {
        $websites = [];
        foreach ($this->websiteRepository->getList() as $website) {
                $websites[] = $website->getData();
        }
        return $websites;
    }
}

As shown in the above example,

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

Sample Output :

javascript
[
    [
      "website_id" => "0",
      "code" => "admin",
      "name" => "Admin",
      "sort_order" => "0",
      "default_group_id" => "0",
      "is_default" => "0",
    ],
    [
      "website_id" => "1",
      "code" => "base",
      "name" => "Main Website",
      "sort_order" => "0",
      "default_group_id" => "1",
      "is_default" => "1",
    ],
  ]

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

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