Skip to content

Commit fe39d0a

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 779058f commit fe39d0a

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
214214
* @param MimeTypeExtensionMap $mimeTypeExtensionMap
215215
* @param ImageProcessorInterface $imageProcessor
216216
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor
217+
* @param AttributeFilter|null $attributeFilter
217218
* @param CollectionProcessorInterface $collectionProcessor [optional]
218219
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
219220
* @param int $cacheLimit [optional]
@@ -534,7 +535,6 @@ public function save(ProductInterface $product, $saveOptions = false)
534535
{
535536
$assignToCategories = false;
536537
$tierPrices = $product->getData('tier_price');
537-
$productDataToChange = $product->getData();
538538

539539
try {
540540
$existingProduct = $product->getId() ?
@@ -599,15 +599,14 @@ public function save(ProductInterface $product, $saveOptions = false)
599599
$websites = null;
600600
}
601601

602+
$useDefault = [];
602603
if (!empty($existingProduct) && is_array($stores) && is_array($websites)) {
603604
$hasDataChanged = false;
604605
$productAttributes = $product->getAttributes();
605606
if ($productAttributes !== null
606607
&& $product->getStoreId() !== Store::DEFAULT_STORE_ID
607608
&& (count($stores) > 1 || count($websites) === 1)
608609
) {
609-
610-
$useDefault = [];
611610
foreach ($product->getAttributes() as $attribute) {
612611
$defaultValue = $attribute->getDefaultValue();
613612
$attributeCode = $attribute->getAttributeCode();
@@ -624,7 +623,6 @@ public function save(ProductInterface $product, $saveOptions = false)
624623
)
625624
) {
626625
$useDefault[$attributeCode] = '1';
627-
$hasDataChanged = true;
628626
} elseif (!$defaultValue && $value !== null
629627
&& $attribute->getScope() !== EavAttributeInterface::SCOPE_GLOBAL_TEXT
630628
&& $existingProduct->getData($attributeCode) === $value
@@ -636,20 +634,16 @@ public function save(ProductInterface $product, $saveOptions = false)
636634
)
637635
) {
638636
$useDefault[$attributeCode] = '1';
639-
$hasDataChanged = true;
640637
} else {
641638
$useDefault[$attributeCode] = '0';
639+
$hasDataChanged = true;
642640
}
643-
644641
}
645642
if ($hasDataChanged) {
646643
$product->setData('_edit_mode', true);
647644
}
648645
}
649646
}
650-
$productDataArray = $this->extensibleDataObjectConverter
651-
->toNestedArray($product, [], ProductInterface::class);
652-
$productDataArray = array_replace($productDataArray, $product->getData());
653647

654648
$productDataArray = $this->attributeFilter->prepareProductAttributes(
655649
$product,
@@ -658,6 +652,7 @@ public function save(ProductInterface $product, $saveOptions = false)
658652
);
659653
$newProduct = $this->productFactory->create();
660654
$newProduct->setData($productDataArray);
655+
661656
$this->saveProduct($newProduct);
662657

663658
if ($assignToCategories === true && $product->getCategoryIds()) {

0 commit comments

Comments
 (0)