refactor(stock): centralize reservation aggregate

This commit is contained in:
2026-08-25 15:05:23 -03:00
parent d0424c5589
commit ede718e448
18 changed files with 783 additions and 419 deletions

View File

@@ -88,9 +88,9 @@ class UserPurchaseLimitService
$excludedCartId !== null,
fn ($query) => $query->whereKeyNot($excludedCartId),
))
->whereHas('stockReservations', fn ($query) => $query
->whereHas('cart.currentStockReservation', fn ($query) => $query
->where('status', 'active')
->whereNull('purchase_id'))
->whereDoesntHave('purchase'))
->sum('cantidad');
if ($purchasedQuantity + $checkoutQuantity + $reservedCartQuantity + $requestedQuantity > $limit) {
@@ -161,9 +161,9 @@ class UserPurchaseLimitService
->whereHas('cart', fn ($query) => $query
->where('user_id', $userId)
->where('status', 'active'))
->whereHas('stockReservations', fn ($query) => $query
->whereHas('cart.currentStockReservation', fn ($query) => $query
->where('status', 'active')
->whereNull('purchase_id'))
->whereDoesntHave('purchase'))
->groupBy('catalog_item_id')
->pluck('quantity', 'catalog_item_id');