Skip to content

Commit ea9d6fa

Browse files
author
Stanislav Idolov
authored
MAGETWO-85296: #7720: Product Repository saves attribute values for existing product always on "Default Store Level" #967
2 parents 3e083e8 + 198dbac commit ea9d6fa

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,9 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
467467
if (!$ignoreLinksFlag && $ignoreLinksFlag !== null) {
468468
$productLinks = $product->getProductLinks();
469469
}
470-
$productDataArray['store_id'] = (int)$this->storeManager->getStore()->getId();
470+
if (!isset($productDataArray['store_id'])) {
471+
$productDataArray['store_id'] = (int)$this->storeManager->getStore()->getId();
472+
}
471473
$product = $this->initializeProductData($productDataArray, empty($existingProduct));
472474

473475
$this->processLinks($product, $productLinks);

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
/**
1414
* Provide tests for ProductRepository model.
15+
*
16+
* @magentoDbIsolation enabled
17+
* @magentoAppIsolation enabled
1518
*/
1619
class ProductRepositoryTest extends \PHPUnit\Framework\TestCase
1720
{
@@ -122,4 +125,23 @@ public function testCreateWithoutSpecifiedType()
122125
self::assertSame('1.2300', $product->getWeight());
123126
self::assertSame('simple', $product->getTypeId());
124127
}
128+
129+
/**
130+
* Tests product repository update should use provided store code.
131+
*
132+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
133+
*/
134+
public function testProductUpdate()
135+
{
136+
$sku = 'simple';
137+
$nameUpdated = 'updated';
138+
$product = $this->productRepository->get($sku, false, 0);
139+
$product->setName($nameUpdated);
140+
$this->productRepository->save($product);
141+
$product = $this->productRepository->get($sku, false, 0);
142+
self::assertEquals(
143+
$nameUpdated,
144+
$product->getName()
145+
);
146+
}
125147
}

0 commit comments

Comments
 (0)