Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetReservationsQuantity.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $resource;
23 
27  public function __construct(
28  ResourceConnection $resource
29  ) {
30  $this->resource = $resource;
31  }
32 
36  public function execute(string $sku, int $stockId): float
37  {
38  $connection = $this->resource->getConnection();
39  $reservationTable = $this->resource->getTableName('inventory_reservation');
40 
41  $select = $connection->select()
42  ->from($reservationTable, [ReservationInterface::QUANTITY => 'SUM(' . ReservationInterface::QUANTITY . ')'])
43  ->where(ReservationInterface::SKU . ' = ?', $sku)
44  ->where(ReservationInterface::STOCK_ID . ' = ?', $stockId)
45  ->limit(1);
46 
47  $reservationQty = $connection->fetchOne($select);
48  if (false === $reservationQty) {
49  $reservationQty = 0;
50  }
51  return (float)$reservationQty;
52  }
53 }
$resource
Definition: bulk.php:12
$connection
Definition: bulk.php:13