Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
stock_with_sales_channels.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
11 use Magento\InventoryApi\Api\Data\StockInterfaceFactory;
15 
17 $stockFactory = Bootstrap::getObjectManager()->get(StockInterfaceFactory::class);
19 $dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
21 $stockRepository = Bootstrap::getObjectManager()->get(StockRepositoryInterface::class);
22 
24 $stock = $stockFactory->create();
25 $dataObjectHelper->populateWithArray(
26  $stock,
27  [
28  StockInterface::STOCK_ID => 10,
29  StockInterface::NAME => 'stock_with_channels_name',
30  ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => [
31  'sales_channels' => [
32  [
33  SalesChannelInterface::TYPE => SalesChannelInterface::TYPE_WEBSITE,
34  SalesChannelInterface::CODE => 'eu_website',
35  ],
36  [
37  SalesChannelInterface::TYPE => SalesChannelInterface::TYPE_WEBSITE,
38  SalesChannelInterface::CODE => 'us_website',
39  ],
40  ],
41  ],
42  ],
43  StockInterface::class
44 );