@@ -156,8 +156,7 @@ public function testGetJsonSwatchConfigUsedProductImage(): void
156156 public function testGetJsonSwatchConfigUsedWithSwatchImageType (): void
157157 {
158158 $ 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 ' ]);
161160 $ expectedOptions = $ this ->getDefaultOptionsList ();
162161 $ expectedOptions ['option 2 ' ]['value ' ] = $ this ->imageUrlBuilder ->getUrl (
163162 '/m/a/magento_image.jpg ' ,
@@ -249,15 +248,16 @@ private function updateAttributeUseProductImageFlag(): void
249248 *
250249 * @param string $sku
251250 * @param string $imageName
251+ * @param array $imageRoles
252252 * @return void
253253 */
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 {
256259 $ product = $ this ->productRepository ->get ($ sku );
257260 $ product ->setStoreId (Store::DEFAULT_STORE_ID )
258- ->setImage ($ imageName )
259- ->setSmallImage ($ imageName )
260- ->setThumbnail ($ imageName )
261261 ->setData (
262262 'media_gallery ' ,
263263 [
@@ -273,20 +273,10 @@ private function updateProductImage(string $sku, string $imageName): void
273273 ]
274274 )
275275 ->setCanSaveCustomOptions (true );
276- $ this ->productResource ->save ($ product );
277- }
276+ foreach ($ imageRoles as $ role ) {
277+ $ product ->setData ($ role , $ imageName );
278+ }
278279
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 );
290281 }
291282}
292-
0 commit comments