feat(inventory): add InventorySubject enum and integrate into catalog item management

This commit is contained in:
2026-08-12 14:42:30 -03:00
parent 5b089e71b2
commit 8e94cf7856
13 changed files with 280 additions and 6 deletions

View File

@@ -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,
),
]);
}
}