feat(inventory): add InventorySubject enum and integrate into catalog item management
This commit is contained in:
@@ -22,6 +22,7 @@ class StartCheckoutService
|
||||
private readonly UserPurchaseLimitService $purchaseLimits,
|
||||
private readonly CatalogSelectionResolver $selections,
|
||||
private readonly PurchaseItemSnapshotFactory $snapshots,
|
||||
private readonly InsufficientStockMessageBuilder $stockMessages,
|
||||
) {}
|
||||
|
||||
/** @param array<string, mixed> $purchaseData */
|
||||
@@ -128,17 +129,25 @@ class StartCheckoutService
|
||||
|
||||
if ($availableQuantity !== null && $availableQuantity < $line['quantity']) {
|
||||
throw ValidationException::withMessages([
|
||||
"{$line['field']}.cantidad" => __('api.purchase.direct_items_max_stock', [
|
||||
'max' => $availableQuantity,
|
||||
]),
|
||||
"{$line['field']}.cantidad" => $this->stockMessages->build(
|
||||
$line['catalog_item'],
|
||||
$line['selection'],
|
||||
$availableQuantity,
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->inventory->reserve($line['selection'], $line['quantity']);
|
||||
} catch (\InvalidArgumentException) {
|
||||
$availableQuantity = $this->inventory->availableQuantity($line['selection']) ?? 0;
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
"{$line['field']}.cantidad" => __('api.purchase.insufficient_stock'),
|
||||
"{$line['field']}.cantidad" => $this->stockMessages->build(
|
||||
$line['catalog_item'],
|
||||
$line['selection'],
|
||||
$availableQuantity,
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user