88use Magento \Catalog \Helper \Image as ImageHelper ;
99use Magento \Catalog \Model \Product ;
1010use Magento \Theme \Model \ResourceModel \Theme \Collection as ThemeCollection ;
11+ use Magento \Theme \Model \Config \Customization as ThemeCustomizationConfig ;
1112use Magento \Framework \App \Area ;
1213use Magento \Framework \View \ConfigInterface ;
1314
@@ -23,6 +24,11 @@ class Cache
2324 */
2425 protected $ themeCollection ;
2526
27+ /**
28+ * @var ThemeCustomizationConfig
29+ */
30+ protected $ themeCustomizationConfig ;
31+
2632 /**
2733 * @var ImageHelper
2834 */
@@ -41,10 +47,12 @@ class Cache
4147 public function __construct (
4248 ConfigInterface $ viewConfig ,
4349 ThemeCollection $ themeCollection ,
44- ImageHelper $ imageHelper
50+ ImageHelper $ imageHelper ,
51+ ThemeCustomizationConfig $ themeCustomizationConfig
4552 ) {
4653 $ this ->viewConfig = $ viewConfig ;
4754 $ this ->themeCollection = $ themeCollection ;
55+ $ this ->themeCustomizationConfig = $ themeCustomizationConfig ;
4856 $ this ->imageHelper = $ imageHelper ;
4957 }
5058
@@ -58,8 +66,10 @@ public function __construct(
5866 protected function getData ()
5967 {
6068 if (!$ this ->data ) {
69+ $ themes = $ this ->getThemesInUse ();
70+
6171 /** @var \Magento\Theme\Model\Theme $theme */
62- foreach ($ this -> themeCollection -> loadRegisteredThemes () as $ theme ) {
72+ foreach ($ themes as $ theme ) {
6373 $ config = $ this ->viewConfig ->getViewConfig ([
6474 'area ' => Area::AREA_FRONTEND ,
6575 'themeModel ' => $ theme ,
@@ -127,4 +137,20 @@ protected function processImageData(Product $product, array $imageData, $file)
127137
128138 return $ this ;
129139 }
140+
141+ protected function getThemesInUse ()
142+ {
143+ $ themesInUse = [];
144+
145+ $ registeredThemes = $ this ->themeCollection ->loadRegisteredThemes ();
146+ $ storesByThemes = $ this ->themeCustomizationConfig ->getStoresByThemes ();
147+
148+ foreach ($ registeredThemes as $ registeredTheme ) {
149+ if (array_key_exists ($ registeredTheme ->getThemeId (), $ storesByThemes )) {
150+ $ themesInUse [] = $ registeredTheme ;
151+ }
152+ }
153+
154+ return $ themesInUse ;
155+ }
130156}
0 commit comments