@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
{{ count($comp_items) }} {{ __('items in comparison') }}
| {{ __('Product') }} | @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
{{ $name }}
|
@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
{!! price_format($price * $conversion_rate) !!}
@if($compare)
{!! price_format($compare * $conversion_rate) !!}
@endif
|
@endforeach
| {{ __('Brand') }} | @foreach($comp_items as $row) @php $p = $row['product']; @endphp{{ optional($p->brand)->name ?? '-' }} | @endforeach
| {{ __('Category') }} | @foreach($comp_items as $row) @php $p = $row['product']; @endphp{{ optional($p->category)->title ?? '-' }} | @endforeach
| {{ __('Availability') }} | @foreach($comp_items as $row) @php $p = $row['product']; if ($row['type'] === 'simple') $stk = $p->stock; else $stk = ($p->subvariants[0]->stock ?? 0); @endphp@if($stk > 0)✓ {{ __('In Stock') }}@else{{ __('Out of Stock') }}@endif | @endforeach
| {{ __('Description') }} | @foreach($comp_items as $row) @php $p = $row['product']; @endphp{{ \Illuminate\Support\Str::limit(strip_tags($p->des ?? $p->description ?? ''), 120) }} | @endforeach
| {{ __('Action') }} | @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{{ __('View') }} | @endforeach
{{ __('Add products to your comparison list to see them side by side.') }}
{{ __('Browse Products') }}