@extends('front/layout.master') @section('title', __('staticwords.ShoppingCart') . ' | ') @section('body') @php $value = Session::get('cart'); if (Auth::check()) { // Only count rows that will actually render (skip orphans where variant or simple product is missing). $renderableCount = 0; if ($cart_table) { foreach ($cart_table as $row) { if ($row->variant || $row->simple_product) $renderableCount++; } } $count = $renderableCount; $usercart = $count; } else { $count = isset($value) ? count($value) : 0; $usercart = session()->get('cart'); } // Compute subtotal $cartSubtotal = 0; $itemsCount = 0; if (Auth::check() && $cart_table) { foreach ($cart_table as $row) { if ($row->active_cart == 1) { $price = ($row->semi_total != null && $row->semi_total != 0) ? $row->semi_total : $row->price_total; $cartSubtotal += (float) $price; $itemsCount += (int) $row->qty; } } } else if (!empty($value) && is_array($value)) { foreach ($value as $item) { $unit = ($item['varofferprice'] ?? 0) > 0 ? $item['varofferprice'] : ($item['varprice'] ?? 0); $cartSubtotal += $unit * ($item['qty'] ?? 1); $itemsCount += (int) ($item['qty'] ?? 1); } } // Genral settings: cart_amount (free shipping threshold), handlingcharge, chargeterm, min_pur_amount $gset = App\Genral::first(); $freeShipThreshold = (float) ($gset->cart_amount ?? 0); $handlingCharge = (float) ($gset->handlingcharge ?? 0); $handlingTerm = $gset->chargeterm ?? 'fo'; $minPurAmount = (float) ($gset->min_pur_amount ?? 0); $handlingTotal = $handlingTerm === 'pi' ? $handlingCharge * max(1, $itemsCount) : $handlingCharge; $remainingForFree = $freeShipThreshold > 0 ? max(0, $freeShipThreshold - $cartSubtotal) : 0; $progressPct = $freeShipThreshold > 0 ? min(100, ($cartSubtotal / $freeShipThreshold) * 100) : 100; $belowMinPur = $minPurAmount > 0 && $cartSubtotal < $minPurAmount; @endphp

{{ __('Your cart') }}

{{ $count }} {{ __('staticwords.Products') ?? 'items' }} {{ __('staticwords.inyourcart') ?? 'in your cart' }}

← {{ __('Continue shopping') }}
@if($usercart > 0 && $usercart != null)
{{-- Cart items --}}
{{-- Free shipping progress (cart_amount) --}} @if($freeShipThreshold > 0)
@if($remainingForFree > 0)
{{ __('Add') }} {!! price_format($remainingForFree * $conversion_rate) !!} {{ __('more to unlock') }} {{ __('FREE shipping') }}
@else
{{ __('Free shipping unlocked!') }}
@endif
@endif {{-- Min purchase warning (min_pur_amount) --}} @if($belowMinPur)
{{ __('Minimum purchase amount is') }} {!! price_format($minPurAmount * $conversion_rate) !!}. {{ __('Add') }} {!! price_format(($minPurAmount - $cartSubtotal) * $conversion_rate) !!} {{ __('more to checkout.') }}
@endif @if(Session::has('validcurrency'))
{{ __('staticwords.Oscur') ?? 'Currency notice:' }} {{ __('staticwords.CerrorMsg') ?? 'currency error' }}
@endif @if(Auth::check()) @foreach($cart_table as $row) @php $orivar = $row->variant; @endphp @isset($orivar) @php $imgPath = isset($orivar->variantimages) ? url('variantimages/thumbnails/' . $orivar->variantimages['main_image']) : url('images/no-image.png'); $product = $orivar->products ?? $row->product ?? null; $proName = $product ? ($product->name ?? '') : ''; $rowPrice = ($row->semi_total != null && $row->semi_total != 0) ? $row->semi_total : $row->price_total; $unitPrice = $row->qty > 0 ? $rowPrice / $row->qty : $rowPrice; $proUrl = $product ? url('details/' . \Illuminate\Support\Str::slug($product->name, '-') . '/' . $product->id) : '#'; @endphp
{{ $proName }}
active_cart == 1 ? 'checked' : '' }} onclick="checkuncheckproduct({{ $row->id }})" class="mt-1 w-4 h-4 rounded">
@if($product && $product->store)
{{ $product->store->name ?? '' }}
@endif

{{ $proName }}

@php $variantSpecs = []; if (!empty($orivar->variant1) && $orivar->variant1->variant_value) $variantSpecs[] = $orivar->variant1->variant_value; if (!empty($orivar->variant2) && $orivar->variant2->variant_value) $variantSpecs[] = $orivar->variant2->variant_value; if (!empty($orivar->variant3) && $orivar->variant3->variant_value) $variantSpecs[] = $orivar->variant3->variant_value; @endphp @if(count($variantSpecs))
{{ implode(' · ', $variantSpecs) }}
@endif {{-- Stock --}} @if($orivar->stock > 0)
✓ {{ __('In Stock') }}
@else
{{ __('Out of Stock') }}
@endif {{-- Quantity controls --}}
{!! price_format($rowPrice * $conversion_rate) !!}
@if($row->qty > 1)
{!! price_format($unitPrice * $conversion_rate) !!} × {{ $row->qty }}
@endif
@endisset @endforeach @else {{-- Guest cart --}} @if(!empty($value)) @foreach($value as $idx => $item) @php $imgKey = $item['varimage'] ?? $item['image'] ?? null; $imgPath = $imgKey ? url('variantimages/thumbnails/' . $imgKey) : url('images/no-image.png'); $itemName = $item['proname'] ?? $item['name'] ?? ''; $unitPrice = ($item['varofferprice'] ?? 0) > 0 ? $item['varofferprice'] : ($item['varprice'] ?? 0); $itemQty = $item['qty'] ?? 1; $itemTotal = $unitPrice * $itemQty; $itemProId = $item['proid'] ?? $item['pro_id'] ?? null; $guestProUrl = $itemProId ? url('details/' . \Illuminate\Support\Str::slug($itemName, '-') . '/' . $itemProId) : '#'; @endphp

{{ $itemName }}

@php $sp = []; if (!empty($item['vop1'])) $sp[] = $item['vop1']; if (!empty($item['vop2'])) $sp[] = $item['vop2']; if (!empty($item['vop3'])) $sp[] = $item['vop3']; @endphp @if(count($sp))
{{ implode(' · ', $sp) }}
@endif
{{ $itemQty }} +
{{ __('Remove') }}
{!! price_format($itemTotal * $conversion_rate) !!}
@if($itemQty > 1)
{!! price_format($unitPrice * $conversion_rate) !!} × {{ $itemQty }}
@endif
@endforeach @endif @endif {{-- Coupon code --}}

{{ __('Have a coupon code?') }}

@if(Session::has('coupanapplied'))
{{ Session::get('coupanapplied')['code'] }}
@else
@csrf
@php // Coupons any shopper can use: cart-/all-scoped and not past their expiry date. $availableCoupons = \App\Coupan::whereIn('link_by', ['cart', 'all']) ->where(function ($q) { $q->whereNull('expirydate')->orWhere('expirydate', '>=', date('Y-m-d')); }) ->orderBy('id', 'desc')->take(6)->get(); @endphp @if($availableCoupons->count())
{{ __('Available offers') }}
@foreach($availableCoupons as $ac) @php // Amounts can be dirty (e.g. "$25,000,000") — strip non-numeric chars before formatting. $acAmt = (float) preg_replace('/[^0-9.]/', '', (string) $ac->amount); $acMin = (float) preg_replace('/[^0-9.]/', '', (string) $ac->minamount); @endphp @endforeach
@endif @endif
{{-- Order summary --}}
@else {{-- Empty cart --}}

{{ __('Your cart is empty') }}

{{ __('Looks like you haven\'t added anything to your cart yet.') }}

{{ __('Continue Shopping') }}
@endif @endsection @section('script') @endsection