17
17
use Magento \Framework \View \DesignInterface ;
18
18
use Magento \Store \Model \StoreManager ;
19
19
use Magento \Store \Model \StoreManagerInterface ;
20
+ use Magento \Framework \View \DesignLoader ;
20
21
21
22
/**
22
23
* Collect enough information about image rendering on front
23
24
* If you want to add new image, that should render on front you need
24
25
* to configure this class in di.xml
25
26
*
27
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
28
*/
27
29
class Image implements ProductRenderCollectorInterface
28
30
{
@@ -51,6 +53,7 @@ class Image implements ProductRenderCollectorInterface
51
53
52
54
/**
53
55
* @var DesignInterface
56
+ * @deprecated 2.3.0 DesignLoader is used for design theme loading
54
57
*/
55
58
private $ design ;
56
59
@@ -59,6 +62,11 @@ class Image implements ProductRenderCollectorInterface
59
62
*/
60
63
private $ imageRenderInfoFactory ;
61
64
65
+ /**
66
+ * @var DesignLoader
67
+ */
68
+ private $ designLoader ;
69
+
62
70
/**
63
71
* Image constructor.
64
72
* @param ImageFactory $imageFactory
@@ -67,21 +75,25 @@ class Image implements ProductRenderCollectorInterface
67
75
* @param DesignInterface $design
68
76
* @param ImageInterfaceFactory $imageRenderInfoFactory
69
77
* @param array $imageCodes
78
+ * @param DesignLoader $designLoader
70
79
*/
71
80
public function __construct (
72
81
ImageFactory $ imageFactory ,
73
82
State $ state ,
74
83
StoreManagerInterface $ storeManager ,
75
84
DesignInterface $ design ,
76
85
ImageInterfaceFactory $ imageRenderInfoFactory ,
77
- array $ imageCodes = []
86
+ array $ imageCodes = [],
87
+ DesignLoader $ designLoader = null
78
88
) {
79
89
$ this ->imageFactory = $ imageFactory ;
80
90
$ this ->imageCodes = $ imageCodes ;
81
91
$ this ->state = $ state ;
82
92
$ this ->storeManager = $ storeManager ;
83
93
$ this ->design = $ design ;
84
94
$ this ->imageRenderInfoFactory = $ imageRenderInfoFactory ;
95
+ $ this ->designLoader = $ designLoader ?: \Magento \Framework \App \ObjectManager::getInstance ()
96
+ ->get (DesignLoader::class);
85
97
}
86
98
87
99
/**
@@ -124,6 +136,8 @@ public function collect(ProductInterface $product, ProductRenderInterface $produ
124
136
}
125
137
126
138
/**
139
+ * Callback for emulating image creation
140
+ *
127
141
* Callback in which we emulate initialize default design theme, depends on current store, be settings store id
128
142
* from render info
129
143
*
@@ -136,7 +150,7 @@ public function collect(ProductInterface $product, ProductRenderInterface $produ
136
150
public function emulateImageCreating (ProductInterface $ product , $ imageCode , $ storeId , ImageInterface $ image )
137
151
{
138
152
$ this ->storeManager ->setCurrentStore ($ storeId );
139
- $ this ->design -> setDefaultDesignTheme ();
153
+ $ this ->designLoader -> load ();
140
154
141
155
$ imageHelper = $ this ->imageFactory ->create ();
142
156
$ imageHelper ->init ($ product , $ imageCode );
0 commit comments