Commit c2ae5a87 by Angel MAS

cart function

parent 3e3fd5db
......@@ -21,7 +21,11 @@ class CartController extends Controller
public function show()
{
$total = $this->total();
return \Session::get('cart');
$cart = \Session::get('cart');
return view('shop-public::show-cart')
->with('cart', $cart)
->with('total', $total);
}
public function add(Product $product)
......@@ -58,6 +62,9 @@ class CartController extends Controller
public function update(Product $product, $quantity)
{
if ($quantity <= 0) {
return redirect()->back();
}
$cart = \Session::get('cart');
if (!isset($cart[$product->slug])) {
return redirect()->route('cart.show');
......
......@@ -8,7 +8,9 @@
</head>
<body>
<p>
<a href="#">Ver carrito <span>0</span></a>
<a href="{{route('cart.show')}}">Ver carrito
<span>{{\Session::has('cart') ? count(\Session::get('cart')) : 0}}</span>
</a>
</p>
{{-- Aqui toda la estructura del blog--}}
......@@ -18,6 +20,10 @@
<!-- Importante: scripts elementales no remover -->
<script src='https://unpkg.com/sweetalert/dist/sweetalert.min.js'></script>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<!-- ******************************************* -->
......
@extends('shop-public::layout')
@section('pageTitle', 'Tiendita')
@section('content')
@php
setlocale(LC_MONETARY, 'en_US');
......@@ -21,10 +21,10 @@
<h4>Precio: {{money_format('%(#10n', $product->infoSale->sale_price)}}</h4>
<div>
<p>
<a href="#">Agregar al carrito</a>
<a href="{{route('cart.add', $product->slug)}}">Agregar al carrito</a>
</p>
<p>
<a href="#">Ver mas informacion</a>
<a href="{{route('show.shop', $product->slug)}}">Ver mas informacion</a>
</p>
</div>
</div>
......
@extends('shop-public::layout')
@section('pageTitle', 'Carrito')
@section('content')
@php
setlocale(LC_MONETARY, 'en_US');
@endphp
<!--code>
Variables disponibles:
<ul>
<li>$cart</li>
<li>$total</li>
</ul>
</code-->
<div style="width: 50%; margin: 0 auto;">
@if(count($cart))
<div class="cart">
<table class="table" style="width: 100%;" align="right">
<thead>
<tr>
<th>Producto</th>
<th>Precio</th>
<th>Cantidad</th>
<th>Subtotal</th>
<th></th>
</tr>
</thead>
@foreach($cart as $product)
<tbody>
<tr>
<td>{{$product->name}}</td>
<td>{{money_format('%(#10n', $product->infoSale->sale_price)}}</td>
<td>
<input
type="number"
min="1"
value="{{$product->quantity}}"
id="product-{{$product->slug}}">
<a
href="#"
class="btn-update"
data-href="{{ route('cart.update', [$product->slug,'']) }}"
data-slug = "{{ $product->slug }}">
Cambiar
</a>
</td>
<td>{{money_format('%(#10n', ($product->infoSale->sale_price * $product->quantity))}}</td>
<td>
<p>
<a href="{{route('show.shop', $product->slug)}}">Detalle</a>
</p>
<p>
<a href="{{route('cart.remove', $product->slug)}}">Eliminar</a>
</p>
</td>
</tr>
</tbody>
@endforeach
<tr>
<td colspan="4" align="right">
{{money_format('%(#10n', ($total))}}
</td>
</tr>
</table>
<p>
<a href="{{route('cart.trash')}}">
Vaciar carrito de compras
</a>
</p>
<p>
<a href="{{route('main.shop')}}">Ver mas productos</a>
</p>
<p>
<a href="#">Finalizar compra</a>
</p>
</div>
@else
<h1>No hay productos agregados</h1>
<p>
<a href="{{route('main.shop')}}">Visitar productos</a>
</p>
@endif
</div>
@endsection
@section('scripts_extra')
<script type="text/javascript">
// Update item cart
$(".btn-update").on('click', function(e){
e.preventDefault();
var slug = $(this).data('slug');
var href = $(this).data('href');
var quantity = $("#product-" + slug).val();
window.location.href = href + "/" + quantity;
});
</script>
@endsection
\ No newline at end of file
@extends('shop-public::layout')
@section('pageTitle', $product->name)
@section('content')
@php
setlocale(LC_MONETARY, 'en_US');
@endphp
<code>
<ul>
......@@ -10,5 +13,19 @@
<li>$otros</li>
</ul>
</code>
<div style="width: 150px; margin: 5px; float: left;">
<img src="{{asset('storage/'.$product->cover)}}" width="100%" alt="Imagen no disponible">
<h4>{{$product->name}}</h4>
<h4>Precio: {{money_format('%(#10n', $product->infoSale->sale_price)}}</h4>
<div>
<p>
<a href="{{route('cart.add', $product->slug)}}">Agregar al carrito</a>
</p>
<p>
<a href="{{route('main.shop')}}">Ver mas productos</a>
</p>
</div>
</div>
@endsection
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