Skip to content

Commit 042df41

Browse files
author
vadim
committed
1 parent c2e2646 commit 042df41

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@ public function save(ProductInterface $product, $saveOptions = false)
543543
if (!$ignoreLinksFlag && $ignoreLinksFlag !== null) {
544544
$productLinks = $product->getProductLinks();
545545
}
546-
$productDataArray['store_id'] = (int)$this->storeManager->getStore()->getId();
546+
if (!isset($productDataArray['store_id'])) {
547+
$productDataArray['store_id'] = (int) $this->storeManager->getStore()->getId();
548+
}
547549
$product = $this->initializeProductData($productDataArray, empty($existingProduct));
548550

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

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,24 @@ public function testCustomLayout(): void
233233
}
234234
$this->assertTrue($caughtException);
235235
}
236+
237+
/**
238+
* Tests product repository update should use provided store code.
239+
*
240+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
241+
*/
242+
public function testProductUpdate(): void
243+
{
244+
$sku = 'simple';
245+
$nameUpdated = 'updated';
246+
247+
$product = $this->productRepository->get($sku, false, 0);
248+
$product->setName($nameUpdated);
249+
$this->productRepository->save($product);
250+
$product = $this->productRepository->get($sku, false, 0);
251+
self::assertEquals(
252+
$nameUpdated,
253+
$product->getName()
254+
);
255+
}
236256
}

0 commit comments

Comments
 (0)