@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
{{ $count }} {{ __('staticwords.Products') ?? 'items' }} {{ __('staticwords.inyourcart') ?? 'in your cart' }}
{{ __('Looks like you haven\'t added anything to your cart yet.') }}
{{ __('Continue Shopping') }}