@@ -322,12 +322,10 @@ protected function initializeProductData(array $productData, $createNew)
322
322
unset($ productData ['media_gallery ' ]);
323
323
if ($ createNew ) {
324
324
$ product = $ this ->productFactory ->create ();
325
+ $ this ->assignProductToWebsites ($ product );
325
326
if (isset ($ productData ['price ' ]) && !isset ($ productData ['product_type ' ])) {
326
327
$ product ->setTypeId (Product \Type::TYPE_SIMPLE );
327
328
}
328
- if ($ this ->storeManager ->hasSingleStore ()) {
329
- $ product ->setWebsiteIds ([$ this ->storeManager ->getStore (true )->getWebsiteId ()]);
330
- }
331
329
} else {
332
330
if (!empty ($ productData ['id ' ])) {
333
331
unset($ this ->instancesById [$ productData ['id ' ]]);
@@ -341,31 +339,20 @@ protected function initializeProductData(array $productData, $createNew)
341
339
foreach ($ productData as $ key => $ value ) {
342
340
$ product ->setData ($ key , $ value );
343
341
}
344
- $ this ->assignProductToWebsites ($ product , $ createNew );
345
342
346
343
return $ product ;
347
344
}
348
345
349
346
/**
350
347
* @param \Magento\Catalog\Model\Product $product
351
- * @param bool $createNew
352
348
* @return void
353
349
*/
354
- private function assignProductToWebsites (\Magento \Catalog \Model \Product $ product, $ createNew )
350
+ private function assignProductToWebsites (\Magento \Catalog \Model \Product $ product )
355
351
{
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 ) {
368
353
$ websiteIds = array_keys ($ this ->storeManager ->getWebsites ());
354
+ } else {
355
+ $ websiteIds = [$ this ->storeManager ->getStore ()->getWebsiteId ()];
369
356
}
370
357
371
358
$ product ->setWebsiteIds ($ websiteIds );
0 commit comments