public function StockServiceManager::receiveStock in Commerce Stock 8
Receive stock.
Parameters
\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity (most likely a product variation entity).
int $location_id: The location ID.
string $zone: The zone.
float $quantity: The quantity.
float $unit_cost: The unit cost.
string $currency_code: The currency code.
string $message: The message.
Overrides StockTransactionsInterface::receiveStock
File
- src/
StockServiceManager.php, line 133
Class
- StockServiceManager
- The stock service manager.
Namespace
Drupal\commerce_stockCode
public function receiveStock(PurchasableEntityInterface $entity, $location_id, $zone, $quantity, $unit_cost, $currency_code, $message = NULL) {
$transaction_type_id = StockTransactionsInterface::NEW_STOCK;
if (is_null($message)) {
$metadata = [];
}
else {
$metadata = [
'data' => [
'message' => $message,
],
];
}
// Make sure quantity is positive.
$quantity = abs($quantity);
$stock_updater = $this
->getService($entity)
->getStockUpdater();
$stock_updater
->createTransaction($entity, $location_id, $zone, $quantity, $unit_cost, $currency_code, $transaction_type_id, $metadata);
}