55 */
66namespace Magento \Theme \Model \Config ;
77
8+ use Magento \Framework \App \Area ;
9+ use Magento \Framework \App \ObjectManager ;
10+ use Magento \Framework \View \Design \Theme \ThemeProviderInterface ;
11+ use Magento \Framework \View \Design \ThemeInterface ;
12+ use Magento \Framework \View \DesignInterface ;
13+ use Magento \Store \Model \Store ;
14+ use Magento \Store \Model \StoreManagerInterface ;
15+ use Magento \Theme \Model \ResourceModel \Theme \Collection ;
16+ use Magento \Theme \Model \Theme \StoreThemesResolverInterface ;
17+ use Magento \Theme \Model \Theme \StoreUserAgentThemeResolver ;
18+
819/**
920 * Theme customization config model
1021 */
1122class Customization
1223{
1324 /**
14- * @var \Magento\Store\Model\ StoreManagerInterface
25+ * @var StoreManagerInterface
1526 */
1627 protected $ _storeManager ;
1728
1829 /**
19- * @var \Magento\Framework\View\ DesignInterface
30+ * @var DesignInterface
2031 */
2132 protected $ _design ;
2233
2334 /**
24- * @var \Magento\Framework\View\Design\Theme\ ThemeProviderInterface
35+ * @var ThemeProviderInterface
2536 */
2637 protected $ themeProvider ;
2738
@@ -40,20 +51,28 @@ class Customization
4051 * @see self::_prepareThemeCustomizations()
4152 */
4253 protected $ _unassignedTheme ;
54+ /**
55+ * @var StoreUserAgentThemeResolver|mixed|null
56+ */
57+ private $ storeThemesResolver ;
4358
4459 /**
45- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
46- * @param \Magento\Framework\View\DesignInterface $design
47- * @param \Magento\Framework\View\Design\Theme\ThemeProviderInterface $themeProvider
60+ * @param StoreManagerInterface $storeManager
61+ * @param DesignInterface $design
62+ * @param ThemeProviderInterface $themeProvider
63+ * @param StoreThemesResolverInterface|null $storeThemesResolver
4864 */
4965 public function __construct (
50- \Magento \Store \Model \StoreManagerInterface $ storeManager ,
51- \Magento \Framework \View \DesignInterface $ design ,
52- \Magento \Framework \View \Design \Theme \ThemeProviderInterface $ themeProvider
66+ StoreManagerInterface $ storeManager ,
67+ DesignInterface $ design ,
68+ ThemeProviderInterface $ themeProvider ,
69+ ?StoreThemesResolverInterface $ storeThemesResolver = null
5370 ) {
5471 $ this ->_storeManager = $ storeManager ;
5572 $ this ->_design = $ design ;
5673 $ this ->themeProvider = $ themeProvider ;
74+ $ this ->storeThemesResolver = $ storeThemesResolver
75+ ?? ObjectManager::getInstance ()->get (StoreThemesResolverInterface::class);
5776 }
5877
5978 /**
@@ -93,22 +112,23 @@ public function getStoresByThemes()
93112 {
94113 $ storesByThemes = [];
95114 $ stores = $ this ->_storeManager ->getStores ();
96- /** @var $store \Magento\Store\Model\ Store */
115+ /** @var $store Store */
97116 foreach ($ stores as $ store ) {
98- $ themeId = $ this ->_getConfigurationThemeId ($ store );
99- if (!isset ($ storesByThemes [$ themeId ])) {
100- $ storesByThemes [$ themeId ] = [];
117+ foreach ($ this ->storeThemesResolver ->getThemes ($ store ) as $ themeId ) {
118+ if (!isset ($ storesByThemes [$ themeId ])) {
119+ $ storesByThemes [$ themeId ] = [];
120+ }
121+ $ storesByThemes [$ themeId ][] = $ store ;
101122 }
102- $ storesByThemes [$ themeId ][] = $ store ;
103123 }
104124 return $ storesByThemes ;
105125 }
106126
107127 /**
108128 * Check if current theme has assigned to any store
109129 *
110- * @param \Magento\Framework\View\Design\ ThemeInterface $theme
111- * @param null|\Magento\Store\Model\ Store $store
130+ * @param ThemeInterface $theme
131+ * @param null|Store $store
112132 * @return bool
113133 */
114134 public function isThemeAssignedToStore ($ theme , $ store = null )
@@ -133,8 +153,8 @@ public function hasThemeAssigned()
133153 /**
134154 * Is theme assigned to specific store
135155 *
136- * @param \Magento\Framework\View\Design\ ThemeInterface $theme
137- * @param \Magento\Store\Model\ Store $store
156+ * @param ThemeInterface $theme
157+ * @param Store $store
138158 * @return bool
139159 */
140160 protected function _isThemeAssignedToSpecificStore ($ theme , $ store )
@@ -145,37 +165,37 @@ protected function _isThemeAssignedToSpecificStore($theme, $store)
145165 /**
146166 * Get configuration theme id
147167 *
148- * @param \Magento\Store\Model\ Store $store
168+ * @param Store $store
149169 * @return int
150170 */
151171 protected function _getConfigurationThemeId ($ store )
152172 {
153173 return $ this ->_design ->getConfigurationDesignTheme (
154- \ Magento \ Framework \ App \ Area::AREA_FRONTEND ,
174+ Area::AREA_FRONTEND ,
155175 ['store ' => $ store ]
156176 );
157177 }
158178
159179 /**
160180 * Fetch theme customization and sort them out to arrays:
161- * self::_assignedTheme and self::_unassignedTheme.
162181 *
182+ * Set self::_assignedTheme and self::_unassignedTheme.
163183 * NOTE: To get into "assigned" list theme customization not necessary should be assigned to store-view directly.
164184 * It can be set to website or as default theme and be used by store-view via config fallback mechanism.
165185 *
166186 * @return $this
167187 */
168188 protected function _prepareThemeCustomizations ()
169189 {
170- /** @var \Magento\Theme\Model\ResourceModel\Theme\ Collection $themeCollection */
171- $ themeCollection = $ this ->themeProvider ->getThemeCustomizations (\ Magento \ Framework \ App \ Area::AREA_FRONTEND );
190+ /** @var Collection $themeCollection */
191+ $ themeCollection = $ this ->themeProvider ->getThemeCustomizations (Area::AREA_FRONTEND );
172192
173193 $ assignedThemes = $ this ->getStoresByThemes ();
174194
175195 $ this ->_assignedTheme = [];
176196 $ this ->_unassignedTheme = [];
177197
178- /** @var $theme \Magento\Framework\View\Design\ ThemeInterface */
198+ /** @var $theme ThemeInterface */
179199 foreach ($ themeCollection as $ theme ) {
180200 if (isset ($ assignedThemes [$ theme ->getId ()])) {
181201 $ theme ->setAssignedStores ($ assignedThemes [$ theme ->getId ()]);
0 commit comments