@@ -148,6 +148,31 @@ public function testGetJsonSwatchConfigUsedProductImage(): void
148
148
);
149
149
}
150
150
151
+ /**
152
+ * @magentoDataFixture Magento/Swatches/_files/configurable_product_with_visual_swatch_attribute.php
153
+ * @magentoDataFixture Magento/Catalog/_files/product_image.php
154
+ * @return void
155
+ */
156
+ public function testGetJsonSwatchConfigUsedWithSwatchImageType (): void
157
+ {
158
+ $ this ->updateAttributeUseProductImageFlag ();
159
+ $ this ->updateProductImage ('simple_option_2 ' , '/m/a/magento_image.jpg ' , ['swatch_image ' ]);
160
+ $ expectedOptions = $ this ->getDefaultOptionsList ();
161
+ $ expectedOptions ['option 2 ' ]['value ' ] = $ this ->imageUrlBuilder ->getUrl (
162
+ '/m/a/magento_image.jpg ' ,
163
+ 'swatch_image_base '
164
+ );
165
+ $ expectedOptions ['option 2 ' ]['thumb ' ] = $ this ->imageUrlBuilder ->getUrl (
166
+ '/m/a/magento_image.jpg ' ,
167
+ 'swatch_thumb_base '
168
+ );
169
+ $ this ->assertOptionsData (
170
+ $ this ->serializer ->unserialize ($ this ->block ->getJsonSwatchConfig ()),
171
+ $ expectedOptions ,
172
+ ['swatch_input_type ' => 'visual ' , 'use_product_image_for_swatch ' => 1 ]
173
+ );
174
+ }
175
+
151
176
/**
152
177
* @magentoDataFixture Magento/Swatches/_files/configurable_product_with_visual_swatch_attribute.php
153
178
* @return void
@@ -223,15 +248,16 @@ private function updateAttributeUseProductImageFlag(): void
223
248
*
224
249
* @param string $sku
225
250
* @param string $imageName
251
+ * @param array $imageRoles
226
252
* @return void
227
253
*/
228
- private function updateProductImage (string $ sku , string $ imageName ): void
229
- {
254
+ private function updateProductImage (
255
+ string $ sku ,
256
+ string $ imageName ,
257
+ array $ imageRoles = ['image ' , 'small_image ' , 'thumbnail ' ]
258
+ ): void {
230
259
$ product = $ this ->productRepository ->get ($ sku );
231
260
$ product ->setStoreId (Store::DEFAULT_STORE_ID )
232
- ->setImage ($ imageName )
233
- ->setSmallImage ($ imageName )
234
- ->setThumbnail ($ imageName )
235
261
->setData (
236
262
'media_gallery ' ,
237
263
[
@@ -247,6 +273,10 @@ private function updateProductImage(string $sku, string $imageName): void
247
273
]
248
274
)
249
275
->setCanSaveCustomOptions (true );
276
+ foreach ($ imageRoles as $ role ) {
277
+ $ product ->setData ($ role , $ imageName );
278
+ }
279
+
250
280
$ this ->productResource ->save ($ product );
251
281
}
252
282
}
0 commit comments