Skip to content

Commit de8066c

Browse files
committed
MAGETWO-91497: Product websites are not honored
1 parent 37150ff commit de8066c

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ protected function initializeProductData(array $productData, $createNew)
334334
unset($productData['media_gallery']);
335335
if ($createNew) {
336336
$product = $this->productFactory->create();
337-
if ($this->storeManager->hasSingleStore()) {
338-
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]);
339-
}
337+
$this->assignProductToWebsites($product);
340338
} else {
341339
unset($this->instances[$productData['sku']]);
342340
$product = $this->get($productData['sku']);
@@ -345,9 +343,6 @@ protected function initializeProductData(array $productData, $createNew)
345343
foreach ($productData as $key => $value) {
346344
$product->setData($key, $value);
347345
}
348-
if ($createNew) {
349-
$this->assignProductToWebsites($product);
350-
}
351346

352347
return $product;
353348
}
@@ -358,15 +353,10 @@ protected function initializeProductData(array $productData, $createNew)
358353
*/
359354
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
360355
{
361-
$websiteIds = array_unique(
362-
array_merge(
363-
$product->getWebsiteIds(),
364-
[$this->storeManager->getStore()->getWebsiteId()]
365-
)
366-
);
367-
368356
if ($this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
369357
$websiteIds = array_keys($this->storeManager->getWebsites());
358+
} else {
359+
$websiteIds = [$this->storeManager->getStore()->getWebsiteId()];
370360
}
371361

372362
$product->setWebsiteIds($websiteIds);

0 commit comments

Comments
 (0)