Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-inventory-api
Test
_files
assign_products_to_websites.php
Go to the documentation of this file.
1
<?php
6
declare(strict_types=1);
7
8
use
Magento\Catalog\Api\ProductRepositoryInterface
;
9
use
Magento\Store\Api\WebsiteRepositoryInterface
;
10
use
Magento\TestFramework\Helper\Bootstrap
;
11
12
$objectManager
= Bootstrap::getObjectManager();
13
15
$websiteRepository
=
$objectManager
->get(WebsiteRepositoryInterface::class);
16
$websiteCodes
= [
'eu_website'
,
'us_website'
,
'global_website'
];
17
$websiteIds
= [];
18
foreach
(
$websiteCodes
as
$websiteCode
) {
19
$website
=
$websiteRepository
->get(
$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
);
29
$productRepository
->save(
$product
);
30
}
Magento\TestFramework\Helper\Bootstrap
Definition:
Bootstrap.php:12
$website
$website
Definition:
payment_configuration_rollback.php:38
$websiteIds
$websiteIds
Definition:
assign_products_to_websites.php:17
$skus
foreach($websiteCodes as $websiteCode) $skus
Definition:
assign_products_to_websites.php:23
$websiteRepository
$websiteRepository
Definition:
assign_products_to_websites.php:15
Magento\Catalog\Api\ProductRepositoryInterface
Definition:
ProductRepositoryInterface.php:14
$websiteCodes
$websiteCodes
Definition:
assign_products_to_websites.php:16
$product
$product
Definition:
bundle_product_with_not_visible_children.php:22
$websiteCode
if(!isset($_GET['website_code'])) $websiteCode
Definition:
website.php:11
Magento\Store\Api\WebsiteRepositoryInterface
Definition:
WebsiteRepositoryInterface.php:16
$productRepository
$productRepository
Definition:
assign_products_to_websites.php:25
$objectManager
$objectManager
Definition:
assign_products_to_websites.php:12