@@ -526,7 +526,6 @@ public function save(ProductInterface $product, $saveOptions = false)
526526 $ assignToCategories = false ;
527527 $ tierPrices = $ product ->getData ('tier_price ' );
528528 $ productDataToChange = $ product ->getData ();
529-
530529 try {
531530 $ existingProduct = $ product ->getId () ?
532531 $ this ->getById ($ product ->getId ()) :
@@ -597,14 +596,16 @@ public function save(ProductInterface $product, $saveOptions = false)
597596 && $ product ->getStoreId () !== Store::DEFAULT_STORE_ID
598597 && (count ($ stores ) > 1 || count ($ websites ) === 1 )
599598 ) {
599+ $ imageRoles = ['image ' , 'small_image ' , 'thumbnail ' ];
600600 foreach ($ productAttributes as $ attribute ) {
601601 $ attributeCode = $ attribute ->getAttributeCode ();
602602 $ 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
604606 && $ attribute ->getScope () !== EavAttributeInterface::SCOPE_GLOBAL_TEXT
605607 && !is_array ($ value )
606608 && !$ attribute ->isStatic ()
607- && !array_key_exists ($ attributeCode , $ productDataToChange )
608609 && $ value !== null
609610 && !$ this ->scopeOverriddenValue ->containsValue (
610611 ProductInterface::class,
@@ -618,6 +619,21 @@ public function save(ProductInterface $product, $saveOptions = false)
618619 $ attributeCode === ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY ? false : null
619620 );
620621 $ 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 ;
621637 }
622638 }
623639 if ($ hasDataChanged ) {
0 commit comments