0
我正在使用laravel中的購物車功能,我已經成功地使用了Cart :: add功能,但是當使用Total功能失敗時,總金額大於金額我計算。如何在Laravel中使用全部功能購物車
有什麼建議嗎?謝謝!
這是我的代碼myController的
public function muahang($id){
$product_buy = DB::table('products')->where('id',$id)->first();
Cart::add(array('id'=>$id,'name' =>$product_buy->name,'qty'=>1,'price'=>$product_buy->price,'options'=>array('img'=>$product_buy->image)));
$content = Cart::content();
return redirect()->route('giohang');
}
public function giohang(){
$content = Cart::content();
$total = Cart::total();
return view('user.pages.shopping',compact('content','total'));
}
這是我的看法:
@foreach($content as $content_item)
<tr>
<td class="image">
<a href="#"><img title="product" alt="product" src="{{ asset('resources/upload/'.$content_item->options->img) }}" height="50" width="50"></a>
</td>
<td class="name"><a href="#">{{ $content_item->name }}</a></td>
<td class="quantity"><input type="text" size="1" value="{{ $content_item->qty }}" name="quantity[40]" class="span1"></td>
<td class="total"> <a href="#"><img class="tooltip-test" data-original-title="Update" src="{!! asset('public/user/img/update.png') !!}" alt=""></a>
<a href="#"><img class="tooltip-test" data-original-title="Remove" src="{!! asset('public/user/img/remove.png') !!}" alt=""></a>
</td>
<td class="price">{{ number_format($content_item->price,0,',','.') }} </td>
<td class="total">{{ number_format(($content_item->price * $content_item->qty),0,',','.') }} </td>
</tr>
@endforeach
</table>
</div>
<div class="container">
<div class="pull-right">
<div class="span4 pull-right">
<table class="table table-striped table-bordered ">
<tr>
<td><span class="extra bold totalamout">Total :</span></td>
<td><span class="bold totalamout">{!! $total !!}</span></td>
</tr>
</table>
<input type="submit" value="CheckOut" class="btn btn-orange pull-right">
<input type="submit" value="Continue Shopping" class="btn btn-orange pull-right mr10">
</div>
</div>
</div>
</div>
總()方法基本上計算的總購物車中的所有物品,給那裏的價格和數量。 –