Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetDataToLegacyStockItem.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $resourceConnection;
23 
27  private $getProductIdsBySkus;
28 
33  public function __construct(
34  ResourceConnection $resourceConnection,
35  GetProductIdsBySkusInterface $getProductIdsBySkus
36  ) {
37  $this->resourceConnection = $resourceConnection;
38  $this->getProductIdsBySkus = $getProductIdsBySkus;
39  }
40 
47  public function execute(string $sku, float $quantity, int $status)
48  {
49  $productIds = $this->getProductIdsBySkus->execute([$sku]);
50 
51  if (isset($productIds[$sku])) {
52  $productId = $productIds[$sku];
53 
54  $connection = $this->resourceConnection->getConnection();
55  $connection->update(
56  $this->resourceConnection->getTableName('cataloginventory_stock_item'),
57  [
58  StockItemInterface::QTY => $quantity,
60  ],
61  [
63  'website_id = ?' => 0,
64  ]
65  );
66  }
67  }
68 }
__construct(ResourceConnection $resourceConnection, GetProductIdsBySkusInterface $getProductIdsBySkus)
$status
Definition: order_status.php:8
$connection
Definition: bulk.php:13