Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateLegacyStockStatusView.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
19 {
23  private $schemaSetup;
24 
28  private $defaultStockProvider;
29 
33  private $stockIndexTableNameResolver;
34 
40  public function __construct(
41  SchemaSetupInterface $schemaSetup,
42  DefaultStockProviderInterface $defaultStockProvider,
43  StockIndexTableNameResolverInterface $stockIndexTableNameResolver
44  ) {
45  $this->schemaSetup = $schemaSetup;
46  $this->stockIndexTableNameResolver = $stockIndexTableNameResolver;
47  $this->defaultStockProvider = $defaultStockProvider;
48  }
49 
53  public function getAliases()
54  {
55  return [];
56  }
57 
61  public function apply()
62  {
63  $this->schemaSetup->startSetup();
64  $defaultStockId = $this->defaultStockProvider->getId();
65  $viewToLegacyIndex = $this->stockIndexTableNameResolver->execute($defaultStockId);
66  $legacyStockStatusTable = $this->schemaSetup->getTable('cataloginventory_stock_status');
67  $productTable = $this->schemaSetup->getTable('catalog_product_entity');
68  $sql = "CREATE
69  SQL SECURITY INVOKER
70  VIEW {$viewToLegacyIndex}
71  AS
72  SELECT
73  DISTINCT
74  legacy_stock_status.product_id,
75  legacy_stock_status.website_id,
76  legacy_stock_status.stock_id,
77  legacy_stock_status.qty quantity,
78  legacy_stock_status.stock_status is_salable,
79  product.sku
80  FROM {$legacyStockStatusTable} legacy_stock_status
81  INNER JOIN {$productTable} product
82  ON legacy_stock_status.product_id = product.entity_id;";
83  $this->schemaSetup->getConnection()->query($sql);
84  $this->schemaSetup->endSetup();
85 
86  return $this;
87  }
88 
92  public static function getDependencies()
93  {
94  return [];
95  }
96 }
__construct(SchemaSetupInterface $schemaSetup, DefaultStockProviderInterface $defaultStockProvider, StockIndexTableNameResolverInterface $stockIndexTableNameResolver)