8
8
use Magento \Catalog \Helper \Image as ImageHelper ;
9
9
use Magento \Catalog \Model \Product ;
10
10
use Magento \Theme \Model \ResourceModel \Theme \Collection as ThemeCollection ;
11
+ use Magento \Theme \Model \Config \Customization as ThemeCustomizationConfig ;
11
12
use Magento \Framework \App \Area ;
12
13
use Magento \Framework \View \ConfigInterface ;
13
14
@@ -23,6 +24,11 @@ class Cache
23
24
*/
24
25
protected $ themeCollection ;
25
26
27
+ /**
28
+ * @var ThemeCustomizationConfig
29
+ */
30
+ protected $ themeCustomizationConfig ;
31
+
26
32
/**
27
33
* @var ImageHelper
28
34
*/
@@ -41,10 +47,12 @@ class Cache
41
47
public function __construct (
42
48
ConfigInterface $ viewConfig ,
43
49
ThemeCollection $ themeCollection ,
44
- ImageHelper $ imageHelper
50
+ ImageHelper $ imageHelper ,
51
+ ThemeCustomizationConfig $ themeCustomizationConfig
45
52
) {
46
53
$ this ->viewConfig = $ viewConfig ;
47
54
$ this ->themeCollection = $ themeCollection ;
55
+ $ this ->themeCustomizationConfig = $ themeCustomizationConfig ;
48
56
$ this ->imageHelper = $ imageHelper ;
49
57
}
50
58
@@ -58,8 +66,10 @@ public function __construct(
58
66
protected function getData ()
59
67
{
60
68
if (!$ this ->data ) {
69
+ $ themes = $ this ->getThemesInUse ();
70
+
61
71
/** @var \Magento\Theme\Model\Theme $theme */
62
- foreach ($ this -> themeCollection -> loadRegisteredThemes () as $ theme ) {
72
+ foreach ($ themes as $ theme ) {
63
73
$ config = $ this ->viewConfig ->getViewConfig ([
64
74
'area ' => Area::AREA_FRONTEND ,
65
75
'themeModel ' => $ theme ,
@@ -127,4 +137,20 @@ protected function processImageData(Product $product, array $imageData, $file)
127
137
128
138
return $ this ;
129
139
}
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
+ }
130
156
}
0 commit comments