7
7
8
8
namespace Magento \Catalog \Model \Product \Image ;
9
9
10
+ use Magento \Framework \App \Area ;
10
11
use Magento \Framework \App \Config \ScopeConfigInterface ;
12
+ use Magento \Framework \App \ObjectManager ;
11
13
use Magento \Framework \View \ConfigInterface ;
14
+ use Magento \Framework \View \Design \Theme \FlyweightFactory ;
15
+ use Magento \Framework \View \Design \ThemeInterface ;
16
+ use Magento \Framework \View \DesignInterface ;
12
17
use Magento \Store \Model \ScopeInterface ;
13
18
use Magento \Catalog \Model \Product \Image ;
14
19
@@ -52,16 +57,43 @@ class ParamsBuilder
52
57
*/
53
58
private $ viewConfig ;
54
59
60
+ /**
61
+ * @var DesignInterface
62
+ */
63
+ private $ design ;
64
+
65
+ /**
66
+ * @var FlyweightFactory
67
+ */
68
+ private $ themeFactory ;
69
+
70
+ /**
71
+ * @var ThemeInterface
72
+ */
73
+ private $ currentTheme ;
74
+
75
+ /**
76
+ * @var array
77
+ */
78
+ private $ themesList = [];
79
+
55
80
/**
56
81
* @param ScopeConfigInterface $scopeConfig
57
82
* @param ConfigInterface $viewConfig
83
+ * @param DesignInterface|null $designInterface
84
+ * @param FlyweightFactory|null $themeFactory
58
85
*/
59
86
public function __construct (
60
87
ScopeConfigInterface $ scopeConfig ,
61
- ConfigInterface $ viewConfig
88
+ ConfigInterface $ viewConfig ,
89
+ DesignInterface $ designInterface = null ,
90
+ FlyweightFactory $ themeFactory = null
62
91
) {
63
92
$ this ->scopeConfig = $ scopeConfig ;
64
93
$ this ->viewConfig = $ viewConfig ;
94
+ $ this ->design = $ designInterface ?? ObjectManager::getInstance ()->get (DesignInterface::class);
95
+ $ this ->themeFactory = $ themeFactory ?? ObjectManager::getInstance ()->get (FlyweightFactory::class);
96
+ $ this ->currentTheme = $ this ->design ->getDesignTheme ();
65
97
}
66
98
67
99
/**
@@ -75,6 +107,8 @@ public function __construct(
75
107
*/
76
108
public function build (array $ imageArguments , int $ scopeId = null ): array
77
109
{
110
+ $ this ->determineCurrentTheme ($ scopeId );
111
+
78
112
$ miscParams = [
79
113
'image_type ' => $ imageArguments ['type ' ] ?? null ,
80
114
'image_height ' => $ imageArguments ['height ' ] ?? null ,
@@ -87,6 +121,22 @@ public function build(array $imageArguments, int $scopeId = null): array
87
121
return array_merge ($ miscParams , $ overwritten , $ watermark );
88
122
}
89
123
124
+ /**
125
+ * @param int|null $scopeId
126
+ * @return void
127
+ */
128
+ private function determineCurrentTheme (int $ scopeId = null ) {
129
+ if (is_numeric ($ scopeId ) || !$ this ->currentTheme ->getId ()) {
130
+ $ themeId = $ this ->design ->getConfigurationDesignTheme (Area::AREA_FRONTEND , ['store ' => $ scopeId ]);
131
+ if (isset ($ this ->themesList [$ themeId ])) {
132
+ $ this ->currentTheme = $ this ->themesList [$ themeId ];
133
+ } else {
134
+ $ this ->currentTheme = $ this ->themeFactory ->create ($ themeId );
135
+ $ this ->themesList [$ themeId ] = $ this ->currentTheme ;
136
+ }
137
+ }
138
+ }
139
+
90
140
/**
91
141
* Overwrite default values
92
142
*
@@ -170,7 +220,11 @@ private function getWatermark(string $type, int $scopeId = null): array
170
220
*/
171
221
private function hasDefaultFrame (): bool
172
222
{
173
- return (bool ) $ this ->viewConfig ->getViewConfig (['area ' => \Magento \Framework \App \Area::AREA_FRONTEND ])
174
- ->getVarValue ('Magento_Catalog ' , 'product_image_white_borders ' );
223
+ return (bool ) $ this ->viewConfig ->getViewConfig (
224
+ [
225
+ 'area ' => \Magento \Framework \App \Area::AREA_FRONTEND ,
226
+ 'themeModel ' => $ this ->currentTheme
227
+ ]
228
+ )->getVarValue ('Magento_Catalog ' , 'product_image_white_borders ' );
175
229
}
176
230
}
0 commit comments