Skip to content

Commit b91c4fd

Browse files
committed
MAGETWO-91402: Product websites are not honored
1 parent aa4b734 commit b91c4fd

File tree

3 files changed

+203
-107
lines changed

3 files changed

+203
-107
lines changed

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,10 @@ protected function initializeProductData(array $productData, $createNew)
322322
unset($productData['media_gallery']);
323323
if ($createNew) {
324324
$product = $this->productFactory->create();
325+
$this->assignProductToWebsites($product);
325326
if (isset($productData['price']) && !isset($productData['product_type'])) {
326327
$product->setTypeId(Product\Type::TYPE_SIMPLE);
327328
}
328-
if ($this->storeManager->hasSingleStore()) {
329-
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]);
330-
}
331329
} else {
332330
if (!empty($productData['id'])) {
333331
unset($this->instancesById[$productData['id']]);
@@ -341,31 +339,20 @@ protected function initializeProductData(array $productData, $createNew)
341339
foreach ($productData as $key => $value) {
342340
$product->setData($key, $value);
343341
}
344-
$this->assignProductToWebsites($product, $createNew);
345342

346343
return $product;
347344
}
348345

349346
/**
350347
* @param \Magento\Catalog\Model\Product $product
351-
* @param bool $createNew
352348
* @return void
353349
*/
354-
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product, $createNew)
350+
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
355351
{
356-
$websiteIds = $product->getWebsiteIds();
357-
358-
if (!$this->storeManager->hasSingleStore()) {
359-
$websiteIds = array_unique(
360-
array_merge(
361-
$websiteIds,
362-
[$this->storeManager->getStore()->getWebsiteId()]
363-
)
364-
);
365-
}
366-
367-
if ($createNew && $this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
352+
if ($this->storeManager->getStore(true)->getCode() === \Magento\Store\Model\Store::ADMIN_CODE) {
368353
$websiteIds = array_keys($this->storeManager->getWebsites());
354+
} else {
355+
$websiteIds = [$this->storeManager->getStore()->getWebsiteId()];
369356
}
370357

371358
$product->setWebsiteIds($websiteIds);

0 commit comments

Comments
 (0)