Skip to content

Commit 6e10b07

Browse files
committed
AC-2904-v1:: Saving product with non-default store scope causes untouched attributes to become store scoped if loaded using ProductRepository
1 parent 306ba37 commit 6e10b07

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ public function save(ProductInterface $product, $saveOptions = false)
525525
{
526526
$assignToCategories = false;
527527
$tierPrices = $product->getData('tier_price');
528-
528+
$productDataToChange = $product->getData();
529529
try {
530530
$existingProduct = $product->getId() ?
531531
$this->getById($product->getId()) :
@@ -619,6 +619,21 @@ public function save(ProductInterface $product, $saveOptions = false)
619619
$attributeCode === ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY ? false : null
620620
);
621621
$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;
622637
}
623638
}
624639
if ($hasDataChanged) {

0 commit comments

Comments
 (0)