public function LocalStockUpdater::updateLocationStockLevel in Commerce Stock 8
Updates the stock level of an entity at a specific location.
Parameters
int $location_id: The location id.
\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.
1 call to LocalStockUpdater::updateLocationStockLevel()
- LocalStockUpdater::createTransaction in modules/
local_storage/ src/ LocalStockUpdater.php - Create a stock transaction.
File
- modules/
local_storage/ src/ LocalStockUpdater.php, line 159
Class
- LocalStockUpdater
- Class LocalStockUpdater.
Namespace
Drupal\commerce_stock_localCode
public function updateLocationStockLevel($location_id, PurchasableEntityInterface $entity) {
$current_level = $this->checker
->getLocationStockLevel($location_id, $entity);
$last_update = $current_level['last_transaction'];
$latest_txn = $this->checker
->getLocationStockTransactionLatest($location_id, $entity);
$latest_sum = $this->checker
->getLocationStockTransactionSum($location_id, $entity, $last_update, $latest_txn);
$new_level = $current_level['qty'] + $latest_sum;
$this
->setLocationStockLevel($location_id, $entity, $new_level, $latest_txn);
// Do we need to clear the transactions after they have been aggregated?
$transactions_retention = \Drupal::config('commerce_stock_local.transactions')
->get('transactions_retention');
if ($transactions_retention == 'delete') {
$this
->clearLocationStockTransactions($location_id, $entity, $latest_txn);
}
}