@extends('front/layout.master') @section('title', __('staticwords.YourCompareList') . ' - ') @section('body') @php // Clean up invalid/deleted entries if (Session::has('comparison')) { $clist = Session::get('comparison', []); foreach ($clist as $k => $row) { $proid = $row['proid'] ?? null; $rtype = $row['type'] ?? 'variant'; $findpro = $rtype === 'simple' ? App\SimpleProduct::find($proid) : App\Product::find($proid); if (!$findpro || $findpro->status != 1) { unset($clist[$k]); } } Session::put('comparison', array_values($clist)); } $comp_items = collect(Session::get('comparison', []))->map(function ($pro) { $proid = $pro['proid'] ?? null; $ctype = $pro['type'] ?? 'variant'; $product = $ctype === 'simple' ? App\SimpleProduct::find($proid) : App\Product::find($proid); if (!$product || $product->status != 1) return null; return ['product' => $product, 'type' => $ctype, 'proid' => $proid]; })->filter()->values(); @endphp

{{ __('staticwords.YourCompareList') }}

{{ count($comp_items) }} {{ __('items in comparison') }}

@if(count($comp_items)) {{ __('Clear all') }} @endif
@if(count($comp_items))
{{-- Image row --}} @foreach($comp_items as $row) @php $p = $row['product']; $ctype = $row['type']; if ($ctype === 'simple') { $img = $p->thumbnail ? url('images/simple_products/' . $p->thumbnail) : url('images/no-image.png'); $url = route('show.product', ['id' => $p->id, 'slug' => $p->slug]); $name = $p->product_name ?? ''; } else { $orivar = $p->subvariants[0] ?? null; $img = ($orivar && $orivar->variantimages) ? url('variantimages/thumbnails/' . $orivar->variantimages->main_image) : url('images/no-image.png'); $url = $orivar && method_exists($p, 'getURL') ? $p->getURL($orivar) : '#'; $name = $p->name ?? ''; } @endphp @endforeach {{-- Price --}} @foreach($comp_items as $row) @php $p = $row['product']; if ($row['type'] === 'simple') { $price = $p->offer_price > 0 ? $p->offer_price : $p->price; $compare = $p->offer_price > 0 ? $p->price : null; } else { $orivar = $p->subvariants[0] ?? null; if ($orivar) { $pData = ProductPrice::getprice($p, $orivar)->getData(); $mp = (float) ($pData->mainprice ?? 0); $op = (float) ($pData->offerprice ?? 0); $price = ($op > 0 && $op < $mp) ? $op : $mp; $compare = ($op > 0 && $op < $mp) ? $mp : null; } else { $price = 0; $compare = null; } } @endphp @endforeach {{-- Brand --}} @foreach($comp_items as $row) @php $p = $row['product']; @endphp @endforeach {{-- Category --}} @foreach($comp_items as $row) @php $p = $row['product']; @endphp @endforeach {{-- Stock --}} @foreach($comp_items as $row) @php $p = $row['product']; if ($row['type'] === 'simple') $stk = $p->stock; else $stk = ($p->subvariants[0]->stock ?? 0); @endphp @endforeach {{-- Description --}} @foreach($comp_items as $row) @php $p = $row['product']; @endphp @endforeach {{-- Actions --}} @foreach($comp_items as $row) @php $p = $row['product']; if ($row['type'] === 'simple') { $url = route('show.product', ['id' => $p->id, 'slug' => $p->slug]); } else { $orivar = $p->subvariants[0] ?? null; $url = $orivar && method_exists($p, 'getURL') ? $p->getURL($orivar) : '#'; } @endphp @endforeach
{{ __('Product') }}
{{ $name }}
{{ __('Price') }}
{!! price_format($price * $conversion_rate) !!}
@if($compare)
{!! price_format($compare * $conversion_rate) !!}
@endif
{{ __('Brand') }}{{ optional($p->brand)->name ?? '-' }}
{{ __('Category') }}{{ optional($p->category)->title ?? '-' }}
{{ __('Availability') }} @if($stk > 0)✓ {{ __('In Stock') }}@else{{ __('Out of Stock') }}@endif
{{ __('Description') }}{{ \Illuminate\Support\Str::limit(strip_tags($p->des ?? $p->description ?? ''), 120) }}
{{ __('Action') }} {{ __('View') }}
@else

{{ __('Nothing to compare yet') }}

{{ __('Add products to your comparison list to see them side by side.') }}

{{ __('Browse Products') }}
@endif
@endsection