Squashed commit of the following:
commit1dc4e29c69Author: ncoronel <ncoronel@quo.ar> Date: Wed Aug 19 13:58:03 2026 -0300 refactor(reservations): unify expiration command commit093e894cc3Author: ncoronel <ncoronel@quo.ar> Date: Wed Aug 19 13:48:09 2026 -0300 feat(cart): expire abandoned stock reservations commitfdf0f3328fAuthor: ncoronel <ncoronel@quo.ar> Date: Wed Aug 19 12:53:12 2026 -0300 refactor(stock): implement expiration for stock reservations and add configuration commit8d6bcdcc43Author: ncoronel <ncoronel@quo.ar> Date: Wed Aug 19 12:38:21 2026 -0300 refactor(cart): invalidate payment on actual changes commit3206e293ebAuthor: ncoronel <ncoronel@quo.ar> Date: Wed Aug 19 12:24:48 2026 -0300 refactor(cart): own checkout item editing commitaed99bd05eAuthor: ncoronel <ncoronel@quo.ar> Date: Wed Aug 19 12:14:57 2026 -0300 refactor(checkout): remove legacy purchase item reservations commitf1649e0e4bAuthor: ncoronel <ncoronel@quo.ar> Date: Wed Aug 19 12:06:29 2026 -0300 refactor(checkout): materialize purchase items on confirmation commite6c4b40a37Author: ncoronel <ncoronel@quo.ar> Date: Wed Aug 19 12:06:19 2026 -0300 feat(inventory): add traceable cart stock reservations
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Cart\Models\CartItem;
|
||||
use App\Domains\Catalog\Services\StockReservationService;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('carritos', function (Blueprint $table): void {
|
||||
$table->string('origin')->default('user')->after('status');
|
||||
});
|
||||
|
||||
Schema::create('stock_reservations', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('inventory_id')->constrained('inventories')->restrictOnDelete();
|
||||
$table->foreignId('cart_item_id')->nullable()->constrained('carrito_items')->nullOnDelete();
|
||||
$table->foreignId('purchase_id')->nullable()->constrained('compras')->cascadeOnDelete();
|
||||
$table->unsignedInteger('quantity');
|
||||
$table->string('status')->default('active');
|
||||
$table->dateTime('expires_at')->nullable();
|
||||
$table->dateTime('committed_at')->nullable();
|
||||
$table->dateTime('released_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['cart_item_id', 'inventory_id']);
|
||||
$table->index(['purchase_id', 'status']);
|
||||
$table->index(['status', 'expires_at']);
|
||||
});
|
||||
|
||||
CartItem::query()
|
||||
->whereHas('cart', fn ($query) => $query->where('status', 'active'))
|
||||
->with([
|
||||
'catalogItem.inventory',
|
||||
'catalogItem.bundleComponents.catalogItem.inventory',
|
||||
'catalogItem.bundleComponents.variant.inventory',
|
||||
'variant.inventory',
|
||||
'variant.catalogItem',
|
||||
])
|
||||
->eachById(function (CartItem $cartItem): void {
|
||||
$selection = $cartItem->selectedItem();
|
||||
if ($selection !== null) {
|
||||
app(StockReservationService::class)->ensure($cartItem, $selection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('stock_reservations');
|
||||
|
||||
Schema::table('carritos', function (Blueprint $table): void {
|
||||
$table->dropColumn('origin');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('compra_items', function (Blueprint $table): void {
|
||||
$table->dropColumn('reservation_status');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('compra_items', function (Blueprint $table): void {
|
||||
$table->string('reservation_status')
|
||||
->default('committed')
|
||||
->after('total');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user