@@ -526,7 +526,6 @@ public function save(ProductInterface $product, $saveOptions = false)
526
526
$ assignToCategories = false ;
527
527
$ tierPrices = $ product ->getData ('tier_price ' );
528
528
$ productDataToChange = $ product ->getData ();
529
-
530
529
try {
531
530
$ existingProduct = $ product ->getId () ?
532
531
$ this ->getById ($ product ->getId ()) :
@@ -597,14 +596,16 @@ public function save(ProductInterface $product, $saveOptions = false)
597
596
&& $ product ->getStoreId () !== Store::DEFAULT_STORE_ID
598
597
&& (count ($ stores ) > 1 || count ($ websites ) === 1 )
599
598
) {
599
+ $ imageRoles = ['image ' , 'small_image ' , 'thumbnail ' ];
600
600
foreach ($ productAttributes as $ attribute ) {
601
601
$ attributeCode = $ attribute ->getAttributeCode ();
602
602
$ value = $ product ->getData ($ attributeCode );
603
- if ($ existingProduct ->getData ($ attributeCode ) === $ value
603
+ if (!in_array ($ attributeCode , $ imageRoles )
604
+ && $ existingProduct ->getData ($ attributeCode ) === $ value
605
+ && $ existingProduct ->getOrigData ($ attributeCode ) === $ value
604
606
&& $ attribute ->getScope () !== EavAttributeInterface::SCOPE_GLOBAL_TEXT
605
607
&& !is_array ($ value )
606
608
&& !$ attribute ->isStatic ()
607
- && !array_key_exists ($ attributeCode , $ productDataToChange )
608
609
&& $ value !== null
609
610
&& !$ this ->scopeOverriddenValue ->containsValue (
610
611
ProductInterface::class,
@@ -618,6 +619,21 @@ public function save(ProductInterface $product, $saveOptions = false)
618
619
$ attributeCode === ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY ? false : null
619
620
);
620
621
$ hasDataChanged = true ;
622
+ } elseif (in_array ($ attributeCode , $ imageRoles )
623
+ && $ existingProduct ->getData ($ attributeCode ) === $ value
624
+ && !array_key_exists ($ attributeCode , $ productDataToChange )
625
+ && $ attribute ->getScope () !== EavAttributeInterface::SCOPE_GLOBAL_TEXT
626
+ && $ value !== null
627
+ && !$ this ->scopeOverriddenValue ->containsValue (
628
+ ProductInterface::class,
629
+ $ product ,
630
+ $ attributeCode ,
631
+ $ product ->getStoreId ()
632
+ )
633
+
634
+ ) {
635
+ $ product ->setData ($ attributeCode , null );
636
+ $ hasDataChanged = true ;
621
637
}
622
638
}
623
639
if ($ hasDataChanged ) {
0 commit comments