@extends('frontend.layout.app') @section('content')

Cart

@php // Calculate all subtotals and platform/gst totals here $cartSubtotal = 0; $totalVendorPlatformFee = 0; $totalVendorGst = 0; foreach ($cartItems as $cartitem) { $itemVendor = $cartitem->vendorProduct; $isVendorItem = !empty($cartitem->vendor_product_id) && $itemVendor; $basePrice = (float) ($cartitem->sp ?? 0); $platformFee = $isVendorItem ? ($basePrice * 0.10) : 0; $gstRate = 0; if ($isVendorItem) { $gstRate = (float) ($itemVendor->gst ?? 0) / 100; } elseif ($cartitem->product && $cartitem->product->gst) { $gstRate = (float) $cartitem->product->gst / 100; } $gstAmount = $basePrice * $gstRate; $effectiveUnitPrice = $basePrice + $platformFee + $gstAmount; $cartSubtotal += $effectiveUnitPrice * $cartitem->quantity; // Sum up platform fee & GST for vendor items if ($isVendorItem) { $totalVendorPlatformFee += $platformFee * $cartitem->quantity; $totalVendorGst += $gstAmount * $cartitem->quantity; } } // Default/fallback shipping cost and method $shippingCost = $shippingCost ?? 0; $shippingMethod = $shippingMethod ?? 'flat'; // Coupon discount from session or 0 $couponDiscount = session('coupon_discount', 0); // Calculate final total (do not allow negative) $orderTotal = max(0, $cartSubtotal + $shippingCost - $couponDiscount); // Minimum cart subtotal for coupon eligibility $minimumCouponSubtotal = 1000; @endphp
@forelse ($cartItems as $cartitem) @php $itemProduct = $cartitem->product; $itemVendor = $cartitem->vendorProduct; $isVendorItem = !empty($cartitem->vendor_product_id); $itemName = $itemVendor->product_name ?? $itemProduct->product_name ?? 'Unknown Product'; $itemUrl = $isVendorItem && $itemVendor ? route('vendor.productsdetails', $itemVendor->id) : route('productsdetails', $itemProduct?->id ?? 0); $fallbackImage = asset('frontend/assets/img/product/default.png'); if ($isVendorItem && $itemVendor && $itemVendor->images && $itemVendor->images->first()) { $imgPath = $itemVendor->images->first()->image ?? null; $imgPath = ltrim((string) $imgPath, '/'); if (str_starts_with($imgPath, 'storage/')) { $imgPath = substr($imgPath, strlen('storage/')); } if (str_starts_with($imgPath, 'public/')) { $imgPath = substr($imgPath, strlen('public/')); } $itemImageUrl = $imgPath ? asset('storage/' . $imgPath) : $fallbackImage; } else { $productImage = $itemProduct && $itemProduct->images ? $itemProduct->images->first() : null; $itemImageUrl = $productImage ? asset('storage/product/' . $productImage->images) : $fallbackImage; } $basePrice = (float) ($cartitem->sp ?? 0); $isVendorItemCalc = $isVendorItem && $itemVendor; $platformFee = $isVendorItemCalc ? ($basePrice * 0.10) : 0; $gstRate = 0; $productGstLabel = ''; if ($isVendorItemCalc) { $gstRate = (float) ($itemVendor->gst ?? 0) / 100; $productGstLabel = $itemVendor->gst ?? '0'; } elseif ($itemProduct && $itemProduct->gst) { $gstRate = (float) $itemProduct->gst / 100; $productGstLabel = $itemProduct->gst ?? '0'; } $gstAmount = $basePrice * $gstRate; $effectiveUnitPrice = $basePrice + $platformFee + $gstAmount; @endphp @empty @endforelse
Image Product Name Price Quantity Total Remove
{{ $itemName }} {{ $itemName }} {{ number_format($effectiveUnitPrice, 2) }} @if($isVendorItemCalc) @elseif($productGstLabel && $productGstLabel > 0) @endif
{{-- Decrease --}} {{-- Quantity --}} {{-- Increase --}} +
{{ number_format($effectiveUnitPrice * $cartitem->quantity, 2) }} @if($isVendorItemCalc) @elseif($productGstLabel && $productGstLabel > 0) @endif
Your cart is empty.
Continue Shopping
@if (count($cartItems) > 0)
@php $coupons = App\Models\Coupon::where('status', 'Active')->get(); @endphp

Cart Totals

{{-- Cart Subtotal --}} @php $totalProductDiscount = 0; $productDiscountsDetail = []; @endphp @foreach ($cartItems as $cartitem) @if (empty($cartitem->vendor_product_id) && isset($cartitem->product->discount) && $cartitem->product->discount > 0) @php // discount is in percent $discountPercent = $cartitem->product->discount; $itemTotal = $cartitem->sp * $cartitem->quantity; $itemProdDiscount = ($discountPercent / 100) * $itemTotal; $totalProductDiscount += $itemProdDiscount; $productDiscountsDetail[] = [ 'name' => $cartitem->product->product_name, 'percent' => $discountPercent, 'value' => $itemProdDiscount, ]; @endphp @endif @endforeach @if ($totalProductDiscount > 0) @endif @php // Sum per-product GST only if any non-vendor cart item has GST $gstAmount = 0; $hasGst = false; $productGstBreakdown = []; foreach ($cartItems as $cartitem) { $itemGstSource = null; if (empty($cartitem->vendor_product_id) && isset($cartitem->product->gst)) { $itemGstSource = $cartitem->product->gst; } if ($itemGstSource !== null && $itemGstSource > 0) { $hasGst = true; $itemGstRate = $itemGstSource / 100; $itemGst = $cartitem->sp * $cartitem->quantity * $itemGstRate; $gstAmount += $itemGst; $productGstBreakdown[] = [ 'name' => $cartitem->product->product_name, 'gst_rate' => $itemGstSource, 'gst_value' => $itemGst, ]; } } @endphp @php // Update the orderTotal to include product discounts, shipping and coupon discounts $orderTotal = max( 0, $cartSubtotal + $shippingCost - $couponDiscount - $totalProductDiscount, ); @endphp {{-- Coupon Discount --}} @if ($couponDiscount) @endif {{-- Final Total --}}
Cart Subtotal {{ number_format($cartSubtotal, 2) }}
Product Discounts -{{ number_format($totalProductDiscount, 2) }}
@foreach ($productDiscountsDetail as $pd)
{{ $pd['name'] }}: {{ rtrim(rtrim(number_format($pd['percent'], 2), '0'), '.') }}% (₹{{ number_format($pd['value'], 2) }})
@endforeach
Coupon Discount -{{ number_format($couponDiscount, 2) }}
Coupon {{ session('applied_coupon') }} applied Remove
Order Total {{ number_format($orderTotal, 2) }}
@endif
@endsection