@section('title') {{trans('website.labels.shopping-cart')}} - {{Config::get('website.title')}} @stop @section('container')

{{trans('website.labels.shopping-cart')}}

@if ($errors->cart->count()) @foreach($errors->cart->all() as $error) {{Alert::warning($error)->close()}} @endforeach @endif {{Form::open(['route' => 'cart.store', 'secure' => true])}}
@forelse($cart as $row) @empty @endforelse
{{trans('website.labels.helios')}} {{trans('website.labels.product')}} {{trans('website.labels.quantity')}} {{trans('website.labels.tax-rate')}} {{trans('website.labels.item-price')}} {{trans('website.labels.price')}}
{{$row->book->helios}} {{HTML::image($row->book->image->url('small'), $row->book->title, ['class' => 'img-thumbnail'])}}

{{str_limit($row->book->title, 60)}}


{{str_limit($row->book->author, 55)}}

{{Form::text('quantity[' . $row->rowid . ']', $row->qty)}} {{Form::hidden('rowid', $row->rowid)}}
{{Button::normal()->extraSmall()->prependIcon(Icon::plus())->withAttributes(['class' => 'plus'])}} {{Button::normal()->extraSmall()->prependIcon(Icon::minus())->withAttributes(['class' => 'minus'])}}
{{Button::cart()->small()->prependIcon(Icon::trash())->asLinkTo(route('cart.remove', [$row->rowid]))}}
{{$row->options->vat}}% {{number_format($row->price, 2, ',', ' ')}} € {{number_format($row->subtotal, 2, ',', ' ')}} €
{{trans('website.messages.empty-cart')}}
{{HTML::link(Session::get('url.remember', route('home')), trans('website.labels.continue-shopping'))}}
@if (Cart::count())
{{trans('website.labels.total-with-vat')}} {{number_format(Cart::total(), 2, ',', ' ')}} €
{{Button::accept(trans('website.buttons.proceed-to-checkout'))->appendIcon(Icon::triangle_right())->block()->submit()->withAttributes(['class' => 'top-margin'])}}
@endif
{{Form::close()}}
@stop @section('scripts') @parent function number_format(number, decimals, decPoint, thousandsSep) { decimals = decimals || 0; number = parseFloat(number); if(!decPoint || !thousandsSep) { decPoint = '.'; thousandsSep = ','; } var roundedNumber = Math.round( Math.abs( number ) * ('1e' + decimals) ) + ''; var numbersString = decimals ? roundedNumber.slice(0, decimals * -1) : roundedNumber; var decimalsString = decimals ? roundedNumber.slice(decimals * -1) : ''; var formattedNumber = ""; while(numbersString.length > 3) { formattedNumber += thousandsSep + numbersString.slice(-3); numbersString = numbersString.slice(0,-3); } return (number < 0 ? '-' : '') + numbersString + formattedNumber + (decimalsString ? (decPoint + decimalsString) : ''); } function updateQuantity($item, value) { var prices = {{json_encode(array_map(function($row) { return floatval($row['price']); }, $cart->toArray()))}}; var $quantity = $item.find('input[name^=quantity]'); var quantity = (parseInt($quantity.val())!=NaN) ? parseInt($quantity.val()) : 1; var rowid = $item.find('input[name=rowid]').val(); var $price = $item.find('.price'); if (quantity<=1 && value==-1) $quantity.val(1); else $quantity.val(quantity + value); $price.html(number_format($quantity.val() * prices[rowid], 2, ',', ' ') + ' €'); } function updateTotal() { var prices = {{json_encode(array_map(function($row) { return floatval($row['price']); }, $cart->toArray()))}}; var $total = $('.total .price'); var total = 0; $('input[name^=quantity]').each(function(index) { var quantity = (parseInt($(this).val())!=NaN) ? parseInt($(this).val()) : 1; var rowid = $(this).siblings('input[name=rowid]').val(); total += quantity * prices[rowid]; }); $total.html(number_format(total, 2, ',', ' ') + ' €'); } $('.quantity .plus').on('click', function(event) { var $item = $(this).parents('.item'); updateQuantity($item, 1); updateTotal(); }); $('.quantity .minus').on('click', function(event) { var $item = $(this).parents('.item'); updateQuantity($item, -1); updateTotal(); }); $('input[name^=quantity]').on('change', function(event) { var $item = $(this).parents('.item'); var value = parseInt($(this).val()); if (value==NaN || value<=0) { $(this).val(1); } updateQuantity($item, 0); updateTotal(); }); @stop