You are here

public function LocalStockChecker::getLocationStockTransactionLatest in Commerce Stock 8

Gets the last transaction id for a given location and purchasable entity.

Parameters

int $location_id: Location id.

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

Return value

int The last location stock transaction id.

1 call to LocalStockChecker::getLocationStockTransactionLatest()
LocalStockChecker::getLocationsStockLevels in modules/local_storage/src/LocalStockChecker.php
Gets the stock levels for a set of locations.

File

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

Class

LocalStockChecker
The stock checker implementation for the local stock module.

Namespace

Drupal\commerce_stock_local

Code

public function getLocationStockTransactionLatest($location_id, PurchasableEntityInterface $entity) {
  $query = $this->database
    ->select('commerce_stock_transaction')
    ->condition('location_id', $location_id)
    ->condition('entity_id', $entity
    ->id())
    ->condition('entity_type', $entity
    ->getEntityTypeId());
  $query
    ->addExpression('MAX(id)', 'max_id');
  $result = $query
    ->execute()
    ->fetch();
  return $result && $result->max_id ? $result->max_id : 0;
}