Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BulkConfigurationAssign.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 
20 {
24  private $resourceConnection;
25 
29  private $isSourceItemManagementAllowedForProductType;
30 
34  private $getProductTypesBySkus;
35 
42  public function __construct(
43  ResourceConnection $resourceConnection,
44  GetProductTypesBySkusInterface $getProductTypesBySkus,
45  IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
46  ) {
47  $this->resourceConnection = $resourceConnection;
48  $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
49  $this->getProductTypesBySkus = $getProductTypesBySkus;
50  }
51 
58  public function execute(
59  array $skus,
60  array $sources
61  ) {
62  $tableName = $this->resourceConnection->getTableName('inventory_low_stock_notification_configuration');
63  $connection = $this->resourceConnection->getConnection();
64 
65  $types = $this->getProductTypesBySkus->execute($skus);
66 
67  foreach ($types as $sku => $type) {
68  if ($this->isSourceItemManagementAllowedForProductType->execute($type)) {
69  foreach ($sources as $sourceCode) {
70  try {
71  $connection->insert($tableName, [
75  ]);
76  } catch (DuplicateException $e) {
77  // Skip if source assignment is duplicated
78  continue;
79  }
80  }
81  }
82  }
83  }
84 }
$tableName
Definition: trigger.php:13
foreach($websiteCodes as $websiteCode) $skus
__construct(ResourceConnection $resourceConnection, GetProductTypesBySkusInterface $getProductTypesBySkus, IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType)
$type
Definition: item.phtml:13
$sourceCode
Definition: inventory.phtml:11
$connection
Definition: bulk.php:13