Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MigrateCatalogInventoryNotifyStockQuantityData.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
21 {
25  private $moduleDataSetup;
26 
30  private $defaultSourceProvider;
31 
36  public function __construct(
37  ModuleDataSetupInterface $moduleDataSetup,
38  DefaultSourceProviderInterface $defaultSourceProvider
39  ) {
40  $this->moduleDataSetup = $moduleDataSetup;
41  $this->defaultSourceProvider = $defaultSourceProvider;
42  }
43 
47  public function apply()
48  {
49  $defaultSource = $this->defaultSourceProvider->getCode();
50  $connection = $this->moduleDataSetup->getConnection();
51  $select = $connection->select();
52  $select
53  ->from(
54  ['stock_item' => $this->moduleDataSetup->getTable(StockItem::ENTITY)],
55  [
56  'source_item.' . SourceItemInterface::SOURCE_CODE,
57  'source_item.' . SourceItemInterface::SKU,
58  'stock_item.notify_stock_qty',
59  ]
60  )->join(
61  ['product' => $this->moduleDataSetup->getTable('catalog_product_entity')],
62  'product.entity_id = stock_item.product_id',
63  []
64  )->join(
65  ['source_item' => $this->moduleDataSetup->getTable(SourceItem::TABLE_NAME_SOURCE_ITEM)],
66  'source_item.sku = product.sku',
67  []
68  )->where(
69  'stock_item.use_config_notify_stock_qty = 0'
70  )->where(
71  'source_item.' . SourceItemInterface::SOURCE_CODE . ' = ?',
72  $defaultSource
73  );
74 
75  $sql = $connection->insertFromSelect(
76  $select,
77  $this->moduleDataSetup->getTable('inventory_low_stock_notification_configuration')
78  );
79 
80  $connection->query($sql);
81 
82  return $this;
83  }
84 
88  public static function getDependencies()
89  {
90  return [];
91  }
92 
96  public function getAliases()
97  {
98  return [];
99  }
100 }
__construct(ModuleDataSetupInterface $moduleDataSetup, DefaultSourceProviderInterface $defaultSourceProvider)
$connection
Definition: bulk.php:13