Php 带Laravel的Moltin购物车,添加多个项目
我正在使用Laravel和Moltin Laravel购物车软件包,对此有一个问题,这一切都很好,但当我添加多个项目时,购物车总数会更新,但不会显示该项目 我在购物车中添加了以下内容:Php 带Laravel的Moltin购物车,添加多个项目,php,laravel-4,shopping-cart,Php,Laravel 4,Shopping Cart,我正在使用Laravel和Moltin Laravel购物车软件包,对此有一个问题,这一切都很好,但当我添加多个项目时,购物车总数会更新,但不会显示该项目 我在购物车中添加了以下内容: {{ Form::open(['route' => 'cart']) }} <input type="hidden" name="path" value="{{ Request::path() }}"> <input type="hidden" name="image" v
{{ 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 to Bag</button>
@else
<a href="" class="btn btn-primary">Email us</a>
@endif
{{ Form::close() }}
{{Form::open(['route'=>'cart'])}
@如果($item->stock>0)
添加到包中
@否则
@恩迪夫
{{Form::close()}}
然后我有这个,它显示了手推车上的物品
@foreach($items as $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> Continue Shopping
</a>
</td>
<td>
<a href="/checkout" class="btn btn-success">
Checkout <span class="glyphicon glyphicon-play"></span>
</a>
</td>
</tr>
@foreach($items作为$item)
image}“style=”宽度:72px;高度:72px;">
状态:库存中
£;{{$item->price}}
@endforeach
小计
£;{{$item->price}}
全部的
£;{{Cart::total(false)}
但正如我所说,它只显示了一个项目,但以英镑表示的金额是正确的。我想您忘了正确地包含每个项目的数量。您的
@foreach
中有一行完全不合适:
<input type="email" class="form-control" id="exampleInputEmail1" value="1">
有人对此有相同的问题吗?即使如此,表列表中仍然只显示一个。我进行了var_转储,只看到一个项目,即使其中有3个。请从负责更新购物车项目的路线/控制器发布代码。我只有此方法:公共函数add(){$input=input::all();$product=array('id'=>1,'name'=>$input['product'],'price'=>$input['price'],'colour'=>$input['COLOURE'],'QUOTE'=>$input['QUOTE'],'path'=>$input['path'],'description'=>$input['description']);购物车::插入($product);$items=Cart::内容();返回视图::make('Cart.bag',compact('items');}这就是我需要的部分$item->quantity+=(int)$input['qty'];$product=$item;谢谢
<input type="text" class="form-control" value="{{ $item->qty }}">
public function add() {
$input = Input::all();
// Pass the product ID with the request parameters
$id = $input['id'];
// Try to get the cart item by ID
$item = Cart::item($id)
// If the result if false then the items was not found
// in the cart and you need to create a 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 it was found you just need to update the quantity
$item->quantity += (int) $input['qty'];
$product = $item;
}
Cart::insert($product);
$items = Cart::contents();
return View::make('cart.bag', compact('items'));
}