嗨,我试图将多件商品的总价作为总价,但它显示的是单个产品的总价,图片是:https : //ibb.co/YkZgfXV
这是cart.blade.php的代码:
<table>
<tr class="table-row">
<?php $total_amount = 0; ?>
@foreach($userCart as $cart)
<td class="column-1">
<div class="cart-img-product b-rad-4 o-f-hidden">
<img src="{{ asset('images/backend_images/products/small/'.$cart->image) }}" alt="IMG-PRODUCT">
</div>
</td>
<td class="column-2">{{ $cart->product_name }}</td>
<td class="column-3">PKR: {{ $cart->price }}</td>
<td class="column-4">
<div class="flex-w bo5 of-hidden w-size17">
<a class="cart_quantity_up color1 flex-c-m size7 bg8 eff2" href="{{ url('/cart/update-quantity/'.$cart->id.'/1') }}">+</a>
<input class="size8 m-text18 t-center num-product" type="number" name="quantity" value="{{ $cart->quantity }}">
@if($cart->quantity>1)
<a class="cart_quantity_down color1 flex-c-m size7 bg8 eff2" href="{{ url('/cart/update-quantity/'.$cart->id.'/-1') }}">-</a>
@endif
</div>
</td>
<td class="column-5">PKR: {{ $cart->price }}</td>
<td class="column-6"><a href="{{ url('/cart/delete-product/'.$cart->id)}}">X</a></td>
</tr>
@endforeach
</table>
<!-- Total -->
<div class="flex-w flex-sb-m p-t-26 p-b-30">
@foreach($userCart as $cart)
<span class="m-text22 w-size19 w-full-sm">
Total:
</span>
<span class="m-text21 w-size20 w-full-sm">
PKR: {{ $cart->price*$cart->quantity }}
</span>
@endforeach
</div>
您需要在显示之前计算购物车的总数。像这样的东西:
<div class="flex-w flex-sb-m p-t-26 p-b-30">
@php
$total = 0;
foreach($userCart as $cart) {
$total += ($cart->price * $cart->quantity);
}
@endphp
<span class="m-text22 w-size19 w-full-sm">
Total:
</span>
<span class="m-text21 w-size20 w-full-sm">
PKR: {{ $total }}
</span>
</div>
您可以将上面的 html 原样保留在您的刀片中。此外,视图中不应该有那种逻辑。例如,它应该在控制器中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句