cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 Get a list of stores

SOLVED

Magento 2 Get a list of stores

Hello,

 

I want to do a select field to select a shop and i need to know how can i get all store's names.

 

But i don't know how to get all...

 

Regards

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Magento 2 Get a list of stores

This works for me

public function __construct(
...,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
...
     $this->_storeManager = $storeManager;
}
....
private function getStoreData(){
    $storeManagerDataList = $this->_storeManager->getStores();
     $options = array();
     
     foreach ($storeManagerDataList as $key => $value) {
               $options[] = ['label' => $value['name'].' - '.$value['code'], 'value' => $key];
     }
     return $options;
}

 

View solution in original post

1 REPLY 1

Re: Magento 2 Get a list of stores

This works for me

public function __construct(
...,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
...
     $this->_storeManager = $storeManager;
}
....
private function getStoreData(){
    $storeManagerDataList = $this->_storeManager->getStores();
     $options = array();
     
     foreach ($storeManagerDataList as $key => $value) {
               $options[] = ['label' => $value['name'].' - '.$value['code'], 'value' => $key];
     }
     return $options;
}