You are here

public function LocalStockChecker::getLocationsStockLevels in Commerce Stock 8

Gets the stock levels for a set of locations.

Parameters

\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.

\Drupal\commerce_stock\StockLocationInterface[] $locations: The stock locations.

Return value

array Stock level information indexed by location id with these values:

  • 'qty': The quantity.
  • 'last_transaction': The id of the last transaction.
1 call to LocalStockChecker::getLocationsStockLevels()
LocalStockChecker::getTotalStockLevel in modules/local_storage/src/LocalStockChecker.php
Gets the stock level.

File

modules/local_storage/src/LocalStockChecker.php, line 169

Class

LocalStockChecker
The stock checker implementation for the local stock module.

Namespace

Drupal\commerce_stock_local

Code

public function getLocationsStockLevels(PurchasableEntityInterface $entity, array $locations) {
  $location_levels = [];

  /** @var \Drupal\commerce_stock\StockLocationInterface $location */
  foreach ($locations as $location) {
    $location_id = $location
      ->getId();
    $location_level = $this
      ->getLocationStockLevel($location_id, $entity);
    $latest_txn = $this
      ->getLocationStockTransactionLatest($location_id, $entity);
    $transactions_qty = $this
      ->getLocationStockTransactionSum($location_id, $entity, $location_level['last_transaction'], $latest_txn);
    $location_levels[$location_id] = [
      'qty' => $location_level['qty'],
      'transactions_qty' => $transactions_qty,
    ];
  }
  return $location_levels;
}