Is it possible to get a list of all sites programatically?

2 Answers 2


You can get all site of Store view using below code:

You can use below class for getting a list of store view and Magento store running from store view.

namespace StackExchange\Magento\Model;

class StoreList {

     * @var \Magento\Store\Api\StoreRepositoryInterface
    private $storeRepository;

    public function __construct(
    \Magento\Store\Api\StoreRepositoryInterface  $storeRepository     
   ) {
       $this->storeRepository = $storeRepository;
    public function getAllSiteList()
        $storeviews = $this->storeRepository->getList();
        foreach($storeviews as $store)
            echo $store->getCode();
            echo $store->getName();
            echo $store->getStoreGroupId();
             echo $store->getWebsiteId();

By sites do you mean websites ?

If yes you can use the storeManagerInterface :

protected $_storeManager;

public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager)
    $this->_storeManager = $storeManager;

And in your function :


If you want to retrieve all names or other data you can use a while on it :

foreach ($this->storeManager->getWebsites() as $website) {
   echo $website->getName();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.