Skip to content

Commit aed0f3d

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 1819863 commit aed0f3d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,46 @@ public function save(ProductInterface $product, $saveOptions = false)
620620
$hasDataChanged = true;
621621
}
622622
}
623+
$storeScopedAttributes = [
624+
ProductAttributeInterface::CODE_SEO_FIELD_META_TITLE,
625+
ProductAttributeInterface::CODE_SEO_FIELD_META_DESCRIPTION,
626+
ProductAttributeInterface::CODE_SEO_FIELD_META_KEYWORD,
627+
];
628+
$origDataAttributes = [
629+
ProductAttributeInterface::CODE_NAME,
630+
ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY,
631+
];
632+
foreach ($product->getAttributes() as $attribute) {
633+
$defaultValue = $attribute->getDefaultValue();
634+
$attributeCode = $attribute->getAttributeCode();
635+
$value = $product->getData($attributeCode);
636+
if ($defaultValue
637+
&& $defaultValue === $value
638+
&& $value !== null
639+
&& $attribute->getScope() !== EavAttributeInterface::SCOPE_GLOBAL_TEXT
640+
&& !$this->scopeOverriddenValue->containsValue(
641+
ProductInterface::class,
642+
$product,
643+
$attributeCode,
644+
$product->getStoreId()
645+
)
646+
) {
647+
$product->setData($attributeCode);
648+
$hasDataChanged = true;
649+
} elseif (!$defaultValue && $value !== null
650+
&& $attribute->getScope() === EavAttributeInterface::SCOPE_STORE_TEXT
651+
&& $existingProduct->getData($attributeCode) === $value
652+
&& in_array($attributeCode, $storeScopedAttributes)
653+
) {
654+
$product->setData($attributeCode);
655+
$hasDataChanged = true;
656+
} elseif (in_array($attributeCode, $origDataAttributes)
657+
&& $existingProduct->getOrigData($attributeCode) === $value
658+
) {
659+
$product->setData($attributeCode);
660+
$hasDataChanged = true;
661+
}
662+
}
623663
if ($hasDataChanged) {
624664
$product->setData('_edit_mode', true);
625665
}

0 commit comments

Comments
 (0)