Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoreView.php
Go to the documentation of this file.
1 <?php
2 /***
3  * Copyright © Magento, Inc. All rights reserved.
4  * See COPYING.txt for license details.
5  */
7 
11 
15 class StoreView
16 {
20  private $scopeConfig;
21 
25  private $storeManager;
26 
30  private $themeProvider;
31 
37  public function __construct(
38  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
39  \Magento\Store\Model\StoreManagerInterface $storeManager,
40  \Magento\Framework\View\Design\Theme\ThemeProviderInterface $themeProvider
41  ) {
42  $this->scopeConfig = $scopeConfig;
43  $this->storeManager = $storeManager;
44  $this->themeProvider = $themeProvider;
45  }
46 
52  public function retrieveThemeLocalePairs()
53  {
54  $stores = $this->storeManager->getStores();
55  $localeThemeData = [];
56 
58  foreach ($stores as $store) {
59  $code = $store->getCode();
60  $themeId = $this->scopeConfig->getValue(
63  $code
64  );
65  $localeThemeData[] = [
66  'theme' => $this->themeProvider->getThemeById($themeId)->getCode(),
67  'locale' => $this->scopeConfig->getValue(
70  $code
71  )
72  ];
73  }
74 
75  return $this->removeDuplicates($localeThemeData);
76  }
77 
83  public function retrieveLocales()
84  {
85  $stores = $this->storeManager->getStores();
86  $locales = [];
87 
89  foreach ($stores as $store) {
90  $locales[] = $this->scopeConfig->getValue(
93  $store->getCode()
94  );
95  }
96 
97  return $this->removeDuplicates($locales);
98  }
99 
106  private function removeDuplicates($arr)
107  {
108  $len = count($arr);
109  for ($out = 0; $out < $len; $out++) {
110  $outVal = $arr[$out];
111  for ($in = $out + 1; $in < $len; $in++) {
112  $inVal = $arr[$in];
113  if ($outVal === $inVal) {
114  unset($arr[$out]);
115  }
116  }
117  }
118  return $arr;
119  }
120 }
$storeManager
$locales
Definition: locales.php:14
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\View\Design\Theme\ThemeProviderInterface $themeProvider)
Definition: StoreView.php:37
$code
Definition: info.phtml:12