Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
assign_products_to_websites.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
11 
12 $objectManager = Bootstrap::getObjectManager();
13 
15 $websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
16 $websiteCodes = ['eu_website', 'us_website', 'global_website'];
18 foreach ($websiteCodes as $websiteCode) {
20  $websiteIds[] = $website->getId();
21 }
22 
23 $skus = ['SKU-1', 'SKU-2', 'SKU-3', 'SKU-4'];
25 $productRepository = $objectManager->get(ProductRepositoryInterface::class);
26 foreach ($skus as $sku) {
27  $product = $productRepository->get($sku);
28  $product->setWebsiteIds($websiteIds);
30 }
foreach($websiteCodes as $websiteCode) $skus
if(!isset($_GET['website_code'])) $websiteCode
Definition: website.php:11