How to get all stores collection include the store id 0 in magento 2
-
22-03-2021 - |
Question
Solution
You can use a default Magento store repository \Magento\Store\Api\StoreRepositoryInterface
. Add it as dependency and call the getList
method.
/** @var \Magento\Store\Api\StoreRepositoryInterface $repository */
$stores = $repository->getList();
foreach ($stores as $store) {
echo 'Store: ' . $store->getId();
echo ' --- ';
}
will output all ids:
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange