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
67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Cart\Models;
|
|
|
|
use App\Domains\Catalog\Models\CatalogItem;
|
|
use App\Domains\Catalog\Models\StockReservation;
|
|
use App\Domains\Catalog\Models\Variant;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable([
|
|
'cart_id',
|
|
'catalog_item_id',
|
|
'variant_id',
|
|
'cantidad',
|
|
])]
|
|
class CartItem extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'carrito_items';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'cart_id' => 'integer',
|
|
'catalog_item_id' => 'integer',
|
|
'variant_id' => 'integer',
|
|
'cantidad' => 'integer',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Cart, $this>
|
|
*/
|
|
public function cart(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Cart::class, 'cart_id');
|
|
}
|
|
|
|
/** @return BelongsTo<CatalogItem, $this> */
|
|
public function catalogItem(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CatalogItem::class);
|
|
}
|
|
|
|
/** @return BelongsTo<Variant, $this> */
|
|
public function variant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Variant::class);
|
|
}
|
|
|
|
public function selectedItem(): CatalogItem|Variant|null
|
|
{
|
|
return $this->variant ?? $this->catalogItem;
|
|
}
|
|
|
|
/** @return HasMany<StockReservation, $this> */
|
|
public function stockReservations(): HasMany
|
|
{
|
|
return $this->hasMany(StockReservation::class);
|
|
}
|
|
}
|