@foreach ($products as $key => $product)
slug)}}'>{{$product->name}}
${{currency($product->calculatedFinalPrice['old'])}}
@if($product->variation)
{{$product->variation->name}} {{$product->item->name}}
@endif
@if($has_orders)
${{currency($product->calculatedFinalPrice['old'] * $product->quantity)}}
@else
${{currency($product->calculatedFinalPrice['price'] * $product->quantity)}}
@endif
@if($product->calculatedFinalPrice['has_discount'] && !$has_orders)
${{currency($product->calculatedFinalPrice['old'] * $product->quantity)}}
@endif
@endforeach
@php
// Calculate subtotal using the original prices
$subtotal = $products->sum(function($product){
return $product->calculatedFinalPrice['old'] * $product->quantity;
});
// Calculate the total after all discounts are applied
// (this is what the user will actually pay)
$totalAfterDiscounts = $products->sum(function($product){
return $product->calculatedFinalPrice['price'] * $product->quantity;
});
// For display purposes:
// - If no coupon: show all discounts in the "Descuento" line
// - If coupon: the coupon is shown separately, so "Descuento" shows non-coupon discounts
// But since calculatedFinalPrice already includes all discounts (including coupon),
// we just calculate the total discount as the difference
if(!$has_orders)
{
// If there's a coupon, we want to show it separately
// So we calculate: discount = (subtotal - totalAfterDiscounts) - couponDiscount
// This way "Descuento" shows regular discounts, and coupon shows separately
$totalDiscount = $subtotal - $totalAfterDiscounts;
$couponDiscountAmount = $appliedCoupon ? ($appliedCoupon['discount_amount'] ?? 0) : 0;
// If there's a coupon, subtract it from total discount to avoid double-counting
// since we'll show it on a separate line
$discount = $appliedCoupon ? ($totalDiscount - $couponDiscountAmount) : $totalDiscount;
}
else{
$discount = 0;
}
@endphp
Subtotal
${{currency($subtotal)}}
@if($discount)
Descuento
-${{currency($discount)}}
@endif
@if($appliedCoupon && $appliedCoupon['discount_amount'] > 0)
Descuento cupón ({{$appliedCoupon['coupon_code']}})
-${{currency($appliedCoupon['discount_amount'])}}
@endif
@php
// The final total is already calculated with all discounts applied
$finalTotal = $totalAfterDiscounts;
@endphp
Total
${{currency($finalTotal)}}
@if($alertVendors || $alertTotal)
@else
{{ Aire::open()->route('cart.process')}}
{{ Aire::select($zones, 'zone_id', 'Dirección')->id('states')->value(session('zone_id'))}}
{{ Aire::select([
'express' => 'Envío Express',
'tronex' => 'Envío Tronex'
], 'delivery_method', 'Método de Envío')
->id('delivery_method')
->value('tronex')
}}
Envío Tronex
Entrega en la próxima ruta asignada (Calculando...)
{{Aire::textarea('observations', 'Observaciones')->placeholder('Información adicional')->rows(3)}}
{{ Aire::close() }}
@endif