confirmacion, agregar y quitar productos
This commit is contained in:
parent
784b4d97f8
commit
830002b4cf
1 changed files with 20 additions and 0 deletions
|
@ -96,4 +96,24 @@ class Pedido extends Model
|
||||||
function totalChismosa() : float {
|
function totalChismosa() : float {
|
||||||
return $this->total() + $this->totalTransporte();
|
return $this->total() + $this->totalTransporte();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleConfirm() : bool {
|
||||||
|
$this->confirmed = !$this->confirmed;
|
||||||
|
$this->save();
|
||||||
|
return $this->confirmed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function agregarProducto(Producto $producto, int $cantidad) {
|
||||||
|
$productoEnChismosa = $this->productos()->where('id', $producto->id)->first();
|
||||||
|
if ($productoEnChismosa) {
|
||||||
|
$productoEnChismosa->pivot->cantidad += $cantidad;
|
||||||
|
$productoEnChismosa->save();
|
||||||
|
} else {
|
||||||
|
$this->productos()->attach($producto, ['cantidad' => $cantidad]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function quitarProducto(Producto $producto) {
|
||||||
|
$this->productos()->detach($producto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue