@extends('layouts.customer') @section('title') Check Out @endsection @section('content') @if ($errors->any())
@endif
@csrf @foreach ($cartitem->groupBy('shop_id') as $shopId => $items) @php $sellerTotal = 0; @endphp
Delivery Address

{{Auth::user()->name}} {{Auth::user()->last_name}} ({{Auth::user()->phone}})
@if(\App\Models\Addresses::where('user_id', Auth::user()->id)->where('is_active', 1)->exists()) @else @endif @if(\App\Models\Addresses::where('user_id', Auth::user()->id)->where('is_active', 1)->exists()) @else @endif
@if(\App\Models\Addresses::where('user_id', Auth::user()->id)->where('is_active', 1)->exists()) @else @endif
@if(\App\Models\Addresses::where('user_id', Auth::user()->id)->where('is_active', 1)->exists()) @else @endif
@if(\App\Models\Addresses::where('user_id', Auth::user()->id)->where('is_active', 1)->exists()) @else @endif
@if(\App\Models\Addresses::where('user_id', Auth::user()->id)->where('is_active', 1)->exists()) @else @endif
@php $grandTotal = 0; // Initialize grand total $currentSellerId = null; // Initialize current seller ID @endphp
Order Detail

@php $sellerTotals = []; $grandTotal = 0; @endphp @foreach ($cartitem as $item) @if ($item->status == 1) @php $shopId = $item->products->shop->user_id; $sellerName = $item->products->shop->shop_name; $sellerEmail = $item->products->shop->email; $sellerMunicipal = $item->products->shop->municipal; $sellerBarangay = $item->products->shop->barangay; $sellerPhone = $item->products->shop->phone; $sellerTotal = $item->status == 1 ? $item->products->product_prices->where('is_active', 1)->first()->price * $item->prod_qty : 0; $shippingFee = $item->products->shipping_fee; if (!isset($sellerTotals[$shopId])) { $sellerTotals[$shopId] = [ 'name' => $sellerName, 'email' => $sellerEmail, 'municipal' => $sellerMunicipal, 'barangay' => $sellerBarangay, 'phone' => $sellerPhone, 'total' => 0, ]; } $sellerTotals[$shopId]['total'] += $sellerTotal; $grandTotal += $sellerTotal; @endphp @endif @endforeach @foreach ($sellerTotals as $shopId => $sellerData) Seller Details: {{ $sellerData['email'] }} | {{ $sellerData['phone'] }} | {{ $sellerData['barangay'] }}, {{ $sellerData['municipal'] }} @php $sellerSubtotal = 0; $isWarning = false; @endphp @foreach ($cartitem as $item) @if ($item->status == 1 && $item->products->shop->user_id == $shopId) @php // Get the authenticated user's municipal from addresses table where is_active is 1 $authUserMunicipal = \App\Models\Addresses::where('user_id', Auth::user()->id) ->where('is_active', 1) ->value('municipal'); // Check if the seller's municipal is not the same as the authenticated user's municipal $isWarning = $item->products->shop->municipal !== $authUserMunicipal; @endphp @php $activePrice = optional($item->products->product_prices()->where('is_active', 1)->latest('created_at')->first()); $sellerSubtotal += $activePrice ? $activePrice->price * $item->prod_qty : $item->products->price * $item->prod_qty; @endphp @endif @endforeach @if ($isWarning) @endif
Shop Product Name Quantity Price
{{ $sellerData['name'] }} {{ $item->products->name }} {{ $item->prod_qty }} @php $activePrice = optional($item->products->product_prices()->where('is_active', 1)->latest('created_at')->first()); @endphp @if ($activePrice) {{ number_format($activePrice->price, 2, '.', ',') }} @endif
Total Amount: ₱{{ number_format($sellerSubtotal, 2, '.', ',') }}
Shipping Fee: ₱{{ number_format($shippingFee, 2, '.', ',') }}
Grand Total: ₱{{ number_format($sellerSubtotal + $shippingFee, 2, '.', ',') }}


Warning: Seller's municipal is different from yours. Items are for pick up only.
@php // Fetch shipping fee from delivery_rates table where is_active=1 $shippingRate = \App\Models\DeliveryRate::where('is_active', 1) ->value('delivery_fee'); $shippingFee = $shippingRate ? $shippingRate : 0; @endphp @endforeach
@endforeach
@endsection @section('css') @section('css')