public function LocalStockChecker::getLocationStockLevel in Commerce Stock 8
Gets stock level for a given location and purchasable entity.
Parameters
int $location_id: Location id.
\Drupal\commerce\PurchasableEntityInterface $entity: Purchasable entity.
Return value
array An array of 'qty' and 'last_transaction_id' values.
1 call to LocalStockChecker::getLocationStockLevel()
- 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 69
Class
- LocalStockChecker
- The stock checker implementation for the local stock module.
Namespace
Drupal\commerce_stock_localCode
public function getLocationStockLevel($location_id, PurchasableEntityInterface $entity) {
$result = $this->database
->select('commerce_stock_location_level', 'll')
->fields('ll')
->condition('location_id', $location_id)
->condition('entity_id', $entity
->id())
->condition('entity_type', $entity
->getEntityTypeId())
->execute()
->fetch();
return [
'qty' => $result ? $result->qty : 0,
'last_transaction' => $result ? $result->last_transaction_id : 0,
];
}