@@ -156,8 +156,7 @@ public function testGetJsonSwatchConfigUsedProductImage(): void
156
156
public function testGetJsonSwatchConfigUsedWithSwatchImageType (): void
157
157
{
158
158
$ this ->updateAttributeUseProductImageFlag ();
159
- $ this ->updateProductImage ('simple_option_2 ' , '/m/a/magento_image.jpg ' );
160
- $ this ->setSwatchImage ('simple_option_2 ' , '/m/a/magento_image.jpg ' );
159
+ $ this ->updateProductImage ('simple_option_2 ' , '/m/a/magento_image.jpg ' , ['swatch_image ' ]);
161
160
$ expectedOptions = $ this ->getDefaultOptionsList ();
162
161
$ expectedOptions ['option 2 ' ]['value ' ] = $ this ->imageUrlBuilder ->getUrl (
163
162
'/m/a/magento_image.jpg ' ,
@@ -249,15 +248,16 @@ private function updateAttributeUseProductImageFlag(): void
249
248
*
250
249
* @param string $sku
251
250
* @param string $imageName
251
+ * @param array $imageRoles
252
252
* @return void
253
253
*/
254
- private function updateProductImage (string $ sku , string $ imageName ): void
255
- {
254
+ private function updateProductImage (
255
+ string $ sku ,
256
+ string $ imageName ,
257
+ array $ imageRoles = ['image ' , 'small_image ' , 'thumbnail ' ]
258
+ ): void {
256
259
$ product = $ this ->productRepository ->get ($ sku );
257
260
$ product ->setStoreId (Store::DEFAULT_STORE_ID )
258
- ->setImage ($ imageName )
259
- ->setSmallImage ($ imageName )
260
- ->setThumbnail ($ imageName )
261
261
->setData (
262
262
'media_gallery ' ,
263
263
[
@@ -273,20 +273,10 @@ private function updateProductImage(string $sku, string $imageName): void
273
273
]
274
274
)
275
275
->setCanSaveCustomOptions (true );
276
- $ this ->productResource ->save ($ product );
277
- }
276
+ foreach ($ imageRoles as $ role ) {
277
+ $ product ->setData ($ role , $ imageName );
278
+ }
278
279
279
- /**
280
- * Set swatch image for a Product.
281
- *
282
- * @param string $sku
283
- * @param string $imageName
284
- * @return void
285
- */
286
- private function setSwatchImage (string $ sku , string $ imageName ): void
287
- {
288
- $ product = $ this ->productRepository ->get ($ sku );
289
- $ product ->setSwatchImage ($ imageName )->save ($ product );
280
+ $ this ->productResource ->save ($ product );
290
281
}
291
282
}
292
-
0 commit comments