Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
stock_source_links.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
10 use Magento\InventoryApi\Api\Data\StockSourceLinkInterfaceFactory;
13 
15 $dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
17 $stockSourceLinksSave = Bootstrap::getObjectManager()->get(StockSourceLinksSaveInterface::class);
19 $stockSourceLinkFactory = Bootstrap::getObjectManager()->get(StockSourceLinkInterfaceFactory::class);
20 
37  [
38  StockSourceLinkInterface::STOCK_ID => 10,
39  StockSourceLinkInterface::SOURCE_CODE => 'eu-1',
40  StockSourceLinkInterface::PRIORITY => 1,
41  ],
42  [
43  StockSourceLinkInterface::STOCK_ID => 10,
44  StockSourceLinkInterface::SOURCE_CODE => 'eu-2',
45  StockSourceLinkInterface::PRIORITY => 2,
46  ],
47  [
48  StockSourceLinkInterface::STOCK_ID => 10,
49  StockSourceLinkInterface::SOURCE_CODE => 'eu-3',
50  StockSourceLinkInterface::PRIORITY => 3,
51  ],
52  [
53  StockSourceLinkInterface::STOCK_ID => 10,
54  StockSourceLinkInterface::SOURCE_CODE => 'eu-disabled',
55  StockSourceLinkInterface::PRIORITY => 4,
56  ],
57  [
58  StockSourceLinkInterface::STOCK_ID => 20,
59  StockSourceLinkInterface::SOURCE_CODE => 'us-1',
60  StockSourceLinkInterface::PRIORITY => 1,
61  ],
62  [
63  StockSourceLinkInterface::STOCK_ID => 30,
64  StockSourceLinkInterface::SOURCE_CODE => 'eu-1',
65  StockSourceLinkInterface::PRIORITY => 5,
66  ],
67  [
68  StockSourceLinkInterface::STOCK_ID => 30,
69  StockSourceLinkInterface::SOURCE_CODE => 'eu-2',
70  StockSourceLinkInterface::PRIORITY => 4,
71  ],
72  [
73  StockSourceLinkInterface::STOCK_ID => 30,
74  StockSourceLinkInterface::SOURCE_CODE => 'eu-3',
75  StockSourceLinkInterface::PRIORITY => 3,
76  ],
77  [
78  StockSourceLinkInterface::STOCK_ID => 30,
79  StockSourceLinkInterface::SOURCE_CODE => 'eu-disabled',
80  StockSourceLinkInterface::PRIORITY => 2,
81  ],
82  [
83  StockSourceLinkInterface::STOCK_ID => 30,
84  StockSourceLinkInterface::SOURCE_CODE => 'us-1',
85  StockSourceLinkInterface::PRIORITY => 1,
86  ],
87 ];
88 
89 $links = [];
90 foreach ($linksData as $linkData) {
92  $link = $stockSourceLinkFactory->create();
93  $dataObjectHelper->populateWithArray($link, $linkData, StockSourceLinkInterface::class);
94  $links[] = $link;
95 }