Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CurrencyConfig.php
Go to the documentation of this file.
1 <?php
8 
14 
19 {
23  private $appState;
24 
28  private $config;
29 
33  private $storeManager;
34 
42  public function __construct(
43  State $appState,
44  ScopeConfigInterface $config,
45  StoreManagerInterface $storeManager
46  ) {
47  $this->appState = $appState;
48  $this->config = $config;
49  $this->storeManager = $storeManager;
50  }
51 
58  public function getConfigCurrencies(string $path)
59  {
60  $result = $this->appState->getAreaCode() === Area::AREA_ADMINHTML
61  ? $this->getConfigForAllStores($path)
62  : $this->getConfigForCurrentStore($path);
63  sort($result);
64 
65  return array_unique($result);
66  }
67 
74  private function getConfigForAllStores(string $path)
75  {
76  $storesResult = [[]];
77  foreach ($this->storeManager->getStores() as $store) {
78  $storesResult[] = explode(
79  ',',
80  $this->config->getValue($path, ScopeInterface::SCOPE_STORE, $store->getCode())
81  );
82  }
83 
84  return array_merge(...$storesResult);
85  }
86 
93  private function getConfigForCurrentStore(string $path)
94  {
95  $store = $this->storeManager->getStore();
96 
97  return explode(',', $this->config->getValue($path, ScopeInterface::SCOPE_STORE, $store->getCode()));
98  }
99 }
$config
Definition: fraud_order.php:17
$storeManager
__construct(State $appState, ScopeConfigInterface $config, StoreManagerInterface $storeManager)