@@ -416,7 +416,7 @@ public function testDeleteWithMultiWebsites(): void
416
416
$ product ->setWebsiteIds ([$ defaultWebsiteId , $ secondWebsiteId ]);
417
417
$ this ->productRepository ->save ($ product );
418
418
// Assert that product image has roles in global scope only
419
- $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product );
419
+ $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product, $ imageRoles );
420
420
$ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['image ' ]);
421
421
$ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['small_image ' ]);
422
422
$ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['thumbnail ' ]);
@@ -428,7 +428,7 @@ public function testDeleteWithMultiWebsites(): void
428
428
$ product ->addData (array_fill_keys ($ imageRoles , $ image ));
429
429
$ this ->productRepository ->save ($ product );
430
430
// Assert that roles are assigned to product image for second store
431
- $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product );
431
+ $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product, $ imageRoles );
432
432
$ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['image ' ]);
433
433
$ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['small_image ' ]);
434
434
$ this ->assertEquals ($ image , $ imageRolesPerStore [$ globalScopeId ]['thumbnail ' ]);
@@ -454,7 +454,7 @@ public function testDeleteWithMultiWebsites(): void
454
454
$ this ->assertEmpty ($ product ->getMediaGalleryEntries ());
455
455
$ this ->assertFileDoesNotExist ($ path );
456
456
// Load image roles
457
- $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product );
457
+ $ imageRolesPerStore = $ this ->getProductStoreImageRoles ($ product, $ imageRoles );
458
458
// Assert that image roles are reset on global scope and removed on second store
459
459
// as the product is no longer assigned to second website
460
460
$ this ->assertEquals ('no_selection ' , $ imageRolesPerStore [$ globalScopeId ]['image ' ]);
@@ -466,14 +466,17 @@ public function testDeleteWithMultiWebsites(): void
466
466
467
467
/**
468
468
* @param Product $product
469
+ * @param array $roles
469
470
* @return array
470
471
*/
471
- private function getProductStoreImageRoles (Product $ product ): array
472
+ private function getProductStoreImageRoles (Product $ product, array $ roles = [] ): array
472
473
{
473
474
$ imageRolesPerStore = [];
474
475
$ stores = array_keys ($ this ->storeManager ->getStores (true ));
475
476
foreach ($ this ->galleryResource ->getProductImages ($ product , $ stores ) as $ role ) {
476
- $ imageRolesPerStore [$ role ['store_id ' ]][$ role ['attribute_code ' ]] = $ role ['filepath ' ];
477
+ if (empty ($ roles ) || in_array ($ role ['attribute_code ' ], $ roles )) {
478
+ $ imageRolesPerStore [$ role ['store_id ' ]][$ role ['attribute_code ' ]] = $ role ['filepath ' ];
479
+ }
477
480
}
478
481
return $ imageRolesPerStore ;
479
482
}
0 commit comments