Commit cbdc4da2 by Angel MAS

reserva de productos activa

parent 8ffbb955
......@@ -60,6 +60,7 @@ public function add(Product $product)
$sale->save();
\Session::forget('sale');
}
$cart = \Session::get('cart');
$quantity = 1;
......@@ -68,6 +69,10 @@ public function add(Product $product)
$quantity = $cart[$product->slug]->quantity + 1;
}
if ($this->existencia($product) < $quantity) {
return redirect()->back()->with('maximo', $this->existencia($product));
}
$product->quantity = $quantity;
$cart[$product->slug] = $product;
......@@ -106,8 +111,17 @@ public function update(Product $product, $quantity)
if (!isset($cart[$product->slug])) {
return redirect()->route('cart.show');
}
if ($this->existencia($product) >= $quantity){
$cart[$product->slug]->quantity = $quantity;
\Session::put('cart', $cart);
} else {
//return "maximo ".$this->existencia($product);
return redirect()->back()->with('maximo', $this->existencia($product));
}
return redirect()->route('cart.show');
}
......@@ -655,6 +669,30 @@ public function shipping()
public function testmail()
{
$product = Product::find(3);
$quantity = 0;
$sales = Sale::where('status', 1)->orWhere('status',3)->get();
foreach ($sales as $order) {
$products = $order->products;
foreach($products as $aux){
if ($product->id == $aux->id ) {
$quantity += $aux->pivot->quantity;
}
}
}
return $product->infoSale->quantity - $quantity;
//return $quantity;
//return $sales;
//return $product;
/*$user = \App\User::first();
$orden = Sale::find(27);
......@@ -671,5 +709,25 @@ public function shipping()
}
public function existencia($product)
{
$quantity = 0;
$sales = Sale::where('status',3)->get();
foreach ($sales as $order) {
$products = $order->products;
foreach($products as $aux){
if ($product->id == $aux->id ) {
$quantity += $aux->pivot->quantity;
}
}
}
return $product->infoSale->quantity - $quantity;
}
}
......@@ -19,9 +19,9 @@ class ProductController extends Controller
$products = $category->products()->where('active', true)->paginate(15);
} else {
$products = Product::where('active', true)->paginate(3);
$products = Product::where('active', true)->paginate(15);
}
$otros = Product::where('active', true)->inRandomOrder()->take(3)->get();
$otros = Product::where('active', true)->inRandomOrder()->take(15)->get();
$categories = Category::where('active', true)->get();
return view('shop-public::list')
......
......@@ -70,6 +70,22 @@ $util = new Onestartup\Shop\Libs\Util();
</script>
@endif
@if(Session::has('maximo'))
<script type="text/javascript">
swal("Problemas de existencia en inventario",
"Solo puedes agregar máximo {{Session::get('maximo')}} unidades de este producto",
"warning")
</script>
@endif
@if(Session::has('agotado'))
<script type="text/javascript">
swal("Problemas de existencia en inventario",
"Sentimos las inconveniencias, el producto se encuentra agotado por el momento, puedes enviarnos un correo y nosotos nos comunicaremos a la brevedad",
"warning")
</script>
@endif
@if(Session::has('url_ficha'))
<script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment