Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
sources.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
10 use Magento\InventoryApi\Api\Data\SourceInterfaceFactory;
13 
15 $sourceFactory = Bootstrap::getObjectManager()->get(SourceInterfaceFactory::class);
17 $dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
19 $sourceRepository = Bootstrap::getObjectManager()->get(SourceRepositoryInterface::class);
20 
22  [
23  // define only required and needed for tests fields
24  SourceInterface::SOURCE_CODE => 'eu-1',
25  SourceInterface::NAME => 'EU-source-1',
26  SourceInterface::ENABLED => true,
27  SourceInterface::POSTCODE => 'postcode',
28  SourceInterface::COUNTRY_ID => 'FR',
29  ],
30  [
31  SourceInterface::SOURCE_CODE => 'eu-2',
32  SourceInterface::NAME => 'EU-source-2',
33  SourceInterface::ENABLED => true,
34  SourceInterface::POSTCODE => 'postcode',
35  SourceInterface::COUNTRY_ID => 'FR',
36  ],
37  [
38  SourceInterface::SOURCE_CODE => 'eu-3',
39  SourceInterface::NAME => 'EU-source-3',
40  SourceInterface::ENABLED => true,
41  SourceInterface::POSTCODE => 'postcode',
42  SourceInterface::COUNTRY_ID => 'DE',
43  ],
44  [
45  SourceInterface::SOURCE_CODE => 'eu-disabled',
46  SourceInterface::NAME => 'EU-source-disabled',
47  SourceInterface::ENABLED => false,
48  SourceInterface::POSTCODE => 'postcode',
49  SourceInterface::COUNTRY_ID => 'DE',
50  ],
51  [
52  SourceInterface::SOURCE_CODE => 'us-1',
53  SourceInterface::NAME => 'US-source-1',
54  SourceInterface::ENABLED => true,
55  SourceInterface::POSTCODE => 'postcode',
56  SourceInterface::COUNTRY_ID => 'US',
57  ],
58 ];
59 foreach ($sourcesData as $sourceData) {
61  $source = $sourceFactory->create();
62  $dataObjectHelper->populateWithArray($source, $sourceData, SourceInterface::class);
64 }
$sourceRepository
Definition: sources.php:19
$source
Definition: source.php:23
$sourceFactory
Definition: sources.php:15
$dataObjectHelper
Definition: sources.php:17
$sourcesData
Definition: sources.php:21