Вопрос

I have one configuration field with scope as store view in my module.

System config path: vendor/module/title

I have multiple websites with multiple store views and I want to get values of my field for each store view as an array. I can use looping for website and store views to get value for my field for each store view with below code.

$this->scopeConfig->getValue('vendor/module/title', ScopeInterface::SCOPE_STORE, $scopeCode);

and then store it in an array with store_code or store_id as the key.

Is there any other way I can achieve this? May be without loop?

Это было полезно?

Решение

You may inject the given file path \Magento\Store\Model\StoresConfig in your dependencies and use the function getStoresConfigByPath($path).

This function will return all the store values for a given path.

I hope this function meets your requirement.

Другие советы

add this in your constructor

\Magento\Store\Model\StoreRepository $storeRepo

$stores = $this->storeRepo->getList();
$storeList = array();
foreach ($stores as $store) {
  $storeId = $store["store_id"];
  $storeName = $store["name"];
  $storeList[$storeId] = $storeName;
}
return $storeList;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top