77
88namespace Magento \Catalog \Model \Product \Image ;
99
10+ use Magento \Framework \App \Area ;
1011use Magento \Framework \App \Config \ScopeConfigInterface ;
12+ use Magento \Framework \App \ObjectManager ;
1113use 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 ;
1217use Magento \Store \Model \ScopeInterface ;
1318use Magento \Catalog \Model \Product \Image ;
1419
@@ -52,16 +57,43 @@ class ParamsBuilder
5257 */
5358 private $ viewConfig ;
5459
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+
5580 /**
5681 * @param ScopeConfigInterface $scopeConfig
5782 * @param ConfigInterface $viewConfig
83+ * @param DesignInterface|null $designInterface
84+ * @param FlyweightFactory|null $themeFactory
5885 */
5986 public function __construct (
6087 ScopeConfigInterface $ scopeConfig ,
61- ConfigInterface $ viewConfig
88+ ConfigInterface $ viewConfig ,
89+ DesignInterface $ designInterface = null ,
90+ FlyweightFactory $ themeFactory = null
6291 ) {
6392 $ this ->scopeConfig = $ scopeConfig ;
6493 $ 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 ();
6597 }
6698
6799 /**
@@ -75,6 +107,8 @@ public function __construct(
75107 */
76108 public function build (array $ imageArguments , int $ scopeId = null ): array
77109 {
110+ $ this ->determineCurrentTheme ($ scopeId );
111+
78112 $ miscParams = [
79113 'image_type ' => $ imageArguments ['type ' ] ?? null ,
80114 'image_height ' => $ imageArguments ['height ' ] ?? null ,
@@ -87,6 +121,22 @@ public function build(array $imageArguments, int $scopeId = null): array
87121 return array_merge ($ miscParams , $ overwritten , $ watermark );
88122 }
89123
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+
90140 /**
91141 * Overwrite default values
92142 *
@@ -170,7 +220,11 @@ private function getWatermark(string $type, int $scopeId = null): array
170220 */
171221 private function hasDefaultFrame (): bool
172222 {
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 ' );
175229 }
176230}
0 commit comments