feat: enhance checkout process with cart integration and stock confirmation

This commit is contained in:
2026-07-06 14:06:25 -03:00
parent 6bda3bf013
commit dc32eb9bee
11 changed files with 403 additions and 64 deletions

View File

@@ -85,6 +85,25 @@ class ProductVariant extends Model
$this->save();
}
public function confirmReservedStock(int $amount): void
{
if ($amount < 0) {
throw new \InvalidArgumentException('El monto a confirmar debe ser positivo.');
}
if ($this->stock_real < $amount) {
throw new \InvalidArgumentException('No hay suficiente stock real para confirmar la reserva.');
}
if ($this->stock_reservado < $amount) {
throw new \InvalidArgumentException('No hay suficiente stock reservado para confirmar la reserva.');
}
$this->stock_real -= $amount;
$this->stock_reservado -= $amount;
$this->save();
}
protected function stockTecnico(): Attribute
{
return Attribute::get(fn () => $this->stock_real - $this->stock_reservado);