Merge branch 'refactor/inventory_stock' of https://gitea.quo.ar/tbianchini/shopit-back into refactor/inventory_stock

This commit is contained in:
2026-09-29 08:23:09 -03:00
parent c5aeb19735
commit 96378a6c2e
596 changed files with 239 additions and 7622 deletions

View File

@@ -14,7 +14,6 @@ class PurchaseResponseLoader
=== StorefrontWebsiteType::CHECKOUT_SUMMARY_EVENT;
$relations = [
'tenant',
'event.attachment',
'items.sourceCatalogItem.event.attachment',
'stockReservation',
];

View File

@@ -206,7 +206,6 @@ class StartCheckoutService
fn (array $line): float => $line['selection']->getPrice() * $line['quantity'],
),
$cart->getKey(),
$cartItems->first()?->catalogItem?->event_id,
);
$cart->update(['current_purchase_id' => $purchase->getKey()]);
$this->reservations->attachToPurchase($cart, $purchase, $this->checkoutExpiration());
@@ -274,7 +273,6 @@ class StartCheckoutService
$purchaseData,
$cart->getTotalAmount(),
$cart->getKey(),
$cartItems->first()?->catalogItem?->event_id,
);
$cart->update(['current_purchase_id' => $purchase->getKey()]);
$this->reservations->attachToPurchase($cart, $purchase, $this->checkoutExpiration());
@@ -412,12 +410,10 @@ class StartCheckoutService
array $purchaseData,
float $total,
?int $cartId,
?int $eventId,
): Purchase {
return Purchase::query()->create([
...$purchaseData,
'cart_id' => $cartId,
'event_id' => $eventId,
'tenant_codigo' => $tenant->codigo,
'user_id' => $userId,
'status' => Purchase::STATUS_CREATED,

View File

@@ -2,7 +2,6 @@
namespace App\Domains\Commerce\Purchase\Services;
use App\Domains\Commerce\Catalog\Models\Inventory;
use App\Domains\Commerce\Purchase\Models\Purchase;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
@@ -70,12 +69,15 @@ class TenantTransactionResetService
'users_preserved' => DB::table('users')->where('tenant_codigo', $tenantCode)->count(),
];
Inventory::query()
->whereKey($scope['inventory_ids'])
->orderBy('id')
->lockForUpdate()
->get()
->each(fn (Inventory $inventory) => $inventory->resetTransactionCounters());
DB::table('inventories')
->whereIn('id', $scope['inventory_ids'])
->update([
'real_stock' => DB::raw('real_stock + sold_units - refunded_units'),
'reserved_stock' => 0,
'entry_reserved_stock' => 0,
'sold_units' => 0,
'refunded_units' => 0,
]);
return $summary;
});