@@ -334,9 +334,7 @@ protected function initializeProductData(array $productData, $createNew)
334
334
unset($ productData ['media_gallery ' ]);
335
335
if ($ createNew ) {
336
336
$ product = $ this ->productFactory ->create ();
337
- if ($ this ->storeManager ->hasSingleStore ()) {
338
- $ product ->setWebsiteIds ([$ this ->storeManager ->getStore (true )->getWebsiteId ()]);
339
- }
337
+ $ this ->assignProductToWebsites ($ product );
340
338
} else {
341
339
unset($ this ->instances [$ productData ['sku ' ]]);
342
340
$ product = $ this ->get ($ productData ['sku ' ]);
@@ -345,9 +343,6 @@ protected function initializeProductData(array $productData, $createNew)
345
343
foreach ($ productData as $ key => $ value ) {
346
344
$ product ->setData ($ key , $ value );
347
345
}
348
- if ($ createNew ) {
349
- $ this ->assignProductToWebsites ($ product );
350
- }
351
346
352
347
return $ product ;
353
348
}
@@ -358,15 +353,10 @@ protected function initializeProductData(array $productData, $createNew)
358
353
*/
359
354
private function assignProductToWebsites (\Magento \Catalog \Model \Product $ product )
360
355
{
361
- $ websiteIds = array_unique (
362
- array_merge (
363
- $ product ->getWebsiteIds (),
364
- [$ this ->storeManager ->getStore ()->getWebsiteId ()]
365
- )
366
- );
367
-
368
356
if ($ this ->storeManager ->getStore (true )->getCode () == \Magento \Store \Model \Store::ADMIN_CODE ) {
369
357
$ websiteIds = array_keys ($ this ->storeManager ->getWebsites ());
358
+ } else {
359
+ $ websiteIds = [$ this ->storeManager ->getStore ()->getWebsiteId ()];
370
360
}
371
361
372
362
$ product ->setWebsiteIds ($ websiteIds );
0 commit comments