php - Moltin Cart with Laravel, adding more than one item -
i'm using laravel , moltin laravel-cart bundle , have question works when add together more 1 item cart total updates doesn't show item.
i have next adds cart:
{{ form::open(['route' => 'cart']) }} <input type="hidden" name="path" value="{{ request::path() }}"> <input type="hidden" name="image" value="{{ $item->image }}"> <input type="hidden" name="product" value="{{ $item->name }}"> <input type="hidden" name="description" value="{{ $item->seo_description }}"> <input type="hidden" name="qty" value="1"> <input type="hidden" name="size" value="{{ session::get('size') }}"> <input type="hidden" name="colour" value="{{ session::get('colour') }}"> <input type="hidden" name="price" value="{{ $item->price }}"> @if ($item->stock > 0) <button class="btn btn-success">add bag</button> @else <a href="" class="btn btn-primary">email us</a> @endif {{ form::close() }}
then have shows items of carts.
@foreach($items $item) <tr> <td class="col-sm-8 col-md-6"> <div class="media"> <span class="thumbnail pull-left"> <img class="media-object" src="/uploads/product-images/{{$item->image}}" style="width: 72px; height: 72px;"> </span> <div class="media-body"> <h4 class="media-heading"> <a href="{{ $item->path }}">{{ $item->name }}</a> </h4> <span>status: </span><span class="text-success"><strong>in stock</strong></span> </div> </div> </td> <td class="col-sm-1 col-md-1" style="text-align: center"> <input type="email" class="form-control" id="exampleinputemail1" value="1"> </td> <td class="col-sm-1 col-md-1 text-center"><strong>£{{ $item->price }}</strong></td> <td class="col-sm-1 col-md-1"> </td> </tr> @endforeach <tr> <td></td> <td></td> <td></td> <td><h5>subtotal</h5></td> <td class="text-right"><h5><strong>£{{ $item->price }}</strong></h5></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td><h3>total</h3></td> <td class="text-right"><h3><strong>£{{ cart::total(false) }}</strong></h3></td> </tr> <tr> <td></td> <td></td> <td> <a href="/remove/{{ $item->identifier }}" class="btn btn-danger"> <span class="glyphicon glyphicon-remove"></span> remove </a> </td> <td> <a href="" class="btn btn-default"> <span class="glyphicon glyphicon-shopping-cart"></span> go on shopping </a> </td> <td> <a href="/checkout" class="btn btn-success"> checkout <span class="glyphicon glyphicon-play"></span> </a> </td> </tr>
but said shows 1 item, yet amount in £ correct.
i think forgot include quantity each item correctly. have line that's out of place within @foreach
:
<input type="email" class="form-control" id="exampleinputemail1" value="1">
i think should be:
<input type="text" class="form-control" value="{{ $item->qty }}">
edit cart::insert()
doesn't increment quantity, adds item cart , overrides quantity 1 specified. need check if item in cart when adding , update quantity accordingly. every item added cart must have unique id (so far see you're setting 1
id, not work because cart uses id differentiate between different products. code should this:
public function add() { $input = input::all(); // pass product id request parameters $id = $input['id']; // seek cart item id $item = cart::item($id) // if result if false items not found // in cart , need create new entry if ($item === false) { $product = array( 'id' => $id, 'name' => $input['product'], 'price' => $input['price'], 'colour' => $input['colour'], 'quantity' => $input['qty'], 'image' => $input['image'], 'path' => $input['path'], 'description' => $input['description'] ); } else { // if found need update quantity $item->quantity += (int) $input['qty']; $product = $item; } cart::insert($product); $items = cart::contents(); homecoming view::make('cart.bag', compact('items')); }
php laravel-4 shopping-cart
No comments:
Post a Comment