@php $appliedCoupon = session('applied_coupon'); $isCouponApplied = $appliedCoupon && $appliedCoupon['user_id'] == Auth::id(); @endphp @if (!$isCouponApplied)
@csrf
@else
Coupon applied: {{ $appliedCoupon['code'] }}
@endif @php $userId = Auth::id(); $sessionId = session()->get('session_id'); $cartItems = \App\Models\Cart::where(function ($query) use ($userId, $sessionId) { if ($userId) { $query->where('user_id', $userId); } else { $query->where('session_id', $sessionId); } })->whereNull('order_id')->get(); $totalOriginalPrice = $cartItems->sum('real_amount'); $totalDiscountedPrice = $cartItems->sum('amount'); $totalSaved = max($totalOriginalPrice - $totalDiscountedPrice, 0); $couponDiscount = 0; if (session()->has('applied_coupon')) { $couponData = session('applied_coupon'); $couponDiscount = isset($couponData['discount_amount_type_2']) ? (float) str_replace(',', '', $couponData['discount_amount_type_2']) : 0; } $totalSaved += $couponDiscount; $couponDiscountType2 = session()->get('applied_coupon.discount_amount_type_2', null); $finalPrice = isset($couponDiscountType2) ? max($totalDiscountedPrice - (float) str_replace(',', '', $couponDiscountType2), 0) : $totalDiscountedPrice; $stateTaxes = groupTaxesByState($cartItems); $finalTaxTotal = array_sum($stateTaxes); $finalPrice += $finalTaxTotal; $finalPrice += $cartItems->sum('shipping_method_charges'); @endphp Order Details
Sub Total

${{ number_format($totalOriginalPrice, 2) }}

@if ($totalSaved > 0)
You Save:

${{ number_format($totalSaved, 2) }}

@endif @foreach ($stateTaxes as $state => $taxAmount) @if (!is_null($taxAmount) && $taxAmount > 0)
{{ $state ?? '' }} Tax

${{ number_format($taxAmount, 2) }}

@endif @endforeach @if($cartItems->sum('shipping_method_charges') > 0)
Shipping

${{ number_format($cartItems->sum('shipping_method_charges'), 2) }}

@endif
Total

${{ number_format($finalPrice, 2) }}