{{ $r->title }}
@endif{{ $r->message ?? $r->review ?? '' }}
@extends('front/layout.master') @section('title', "$pro->name") @section('meta_tags') @if(isset($pro->subvariants[0]) && isset($pro->subvariants[0]->variantimages)) @endif @endsection @section('stylesheet') @endsection @section('body') @php // Compute compare + wishlist active state for the detail page $detailInCompare = false; foreach ((array) session('comparison', []) as $cmp) { if (($cmp['proid'] ?? null) == $pro->id && (($cmp['type'] ?? 'variant') === 'variant')) { $detailInCompare = true; break; } } $detailInWish = false; if (auth()->check() && isset($pro->subvariants[0])) { $detailInWish = \App\Wishlist::where('user_id', auth()->id()) ->where('pro_id', $pro->subvariants[0]->id) ->exists(); } // Compute review aggregates $review_t = 0; $price_t = 0; $value_t = 0; $sub_total = 0; $ratings_var = 0; $review_count = count($pro->reviews); $count = $review_count; $onlyrev = []; foreach ($pro->reviews as $review) { $review_t = $review->qty * 5; $price_t = $review->price * 5; $value_t = $review->value * 5; $sub_total = $sub_total + $review_t + $price_t + $value_t; } $denom = ($count * 3) * 5; $overallrating = 0; if ($denom > 0) { $rat = $sub_total / $denom; $ratings_var = ($rat * 100) / 5; $overallrating = ($ratings_var / 2) / 10; } $overallRoundedHalf = floor($overallrating * 2) / 2; // Resolve active variant axes ($pro->variants = AddProductVariant rows; one per attribute axis). // Each row has attr_name = ProductAttribute id, attr_value = JSON array of ProductValue ids. $variantAxes = []; // [ [attribute, valueIds[], selectedValueId|null], ... ] $selectedMap = []; // [attribute_id => value_id] picked from query string foreach ($pro->variants ?? [] as $axisRow) { $attr = \App\ProductAttributes::find($axisRow->attr_name); if (!$attr) continue; $rawValues = $axisRow->attr_value; $valueIds = is_array($rawValues) ? $rawValues : (array) (json_decode((string) $rawValues, true) ?: []); $valueIds = array_values(array_filter(array_map('intval', $valueIds))); if (!$valueIds) continue; $param = request()->query($attr->attr_name); $selected = (is_numeric($param) && in_array((int) $param, $valueIds, true)) ? (int) $param : null; if ($selected !== null) $selectedMap[$attr->id] = $selected; $variantAxes[] = ['attr' => $attr, 'values' => $valueIds, 'selected' => $selected]; } // Pick the subvariant matching every selected axis; fall back to first. $activeVariant = null; foreach ($pro->subvariants as $sv) { $svMap = is_array($sv->main_attr_value) ? $sv->main_attr_value : (array) (json_decode((string) $sv->main_attr_value, true) ?: []); $matchAll = true; foreach ($selectedMap as $aid => $vid) { if (!isset($svMap[$aid]) || (int) $svMap[$aid] !== (int) $vid) { $matchAll = false; break; } } if ($matchAll) { $activeVariant = $sv; break; } } $firstVariant = $activeVariant ?? ($pro->subvariants[0] ?? null); // For axes with no explicit selection, default to whatever the active variant carries. if ($firstVariant) { $svMap = is_array($firstVariant->main_attr_value) ? $firstVariant->main_attr_value : (array) (json_decode((string) $firstVariant->main_attr_value, true) ?: []); foreach ($variantAxes as $i => $axis) { if ($axis['selected'] === null && isset($svMap[$axis['attr']->id])) { $variantAxes[$i]['selected'] = (int) $svMap[$axis['attr']->id]; } } } // Build a query-string preserver so clicking a value flips just that axis. $detailSlug = $pro->slug ?: \Illuminate\Support\Str::slug($pro->name) ?: 'product'; $buildAxisUrl = function ($attrName, $valueId) use ($pro, $variantAxes, $detailSlug) { $params = []; foreach ($variantAxes as $a) { $name = $a['attr']->attr_name; $val = ($name === $attrName) ? $valueId : $a['selected']; if ($val !== null) $params[$name] = $val; } return url('details/' . $detailSlug . '/' . $pro->id) . ($params ? ('?' . http_build_query($params)) : ''); }; $variantImages = $firstVariant && $firstVariant->variantimages ? $firstVariant->variantimages : null; // Compute price using the same helper as the product cards so the detail page // and the cards always agree (mainprice = MRP / strike-through; offerprice = sale). $variantPrice = 0; $variantCompare = null; $disPct = 0; if ($firstVariant) { $priceResp = ProductPrice::getprice($pro, $firstVariant)->getData(); $mp = (float) ($priceResp->mainprice ?? 0); $op = (float) ($priceResp->offerprice ?? 0); $variantPrice = ($op > 0 && $op < $mp) ? $op : $mp; $variantCompare = ($op > 0 && $op < $mp) ? $mp : null; $disPct = ($variantCompare && $variantPrice > 0) ? round((1 - $variantPrice / $variantCompare) * 100) : 0; } // Stock status $totalStock = 0; foreach ($pro->subvariants as $sv) { $totalStock += $sv->stock ?? 0; } // Hide prices for guests when "login to view price" is enabled in general settings. $hidePrice = (\App\Genral::first()->login ?? 0) == 1 && !auth()->check(); // Warranty (stored as w_d + w_my unit + w_type label, e.g. "1 year Warranty") $warrantyParts = array_filter([ trim((string) ($pro->w_d ?? '')), trim((string) ($pro->w_my ?? '')), trim((string) ($pro->w_type ?? '')), ], function($v){ return $v !== ''; }); $warrantyLabel = $warrantyParts ? implode(' ', $warrantyParts) : ''; // Real per-product policy facts (drives the trust badges, the Delivery card, and any other // module that wants to surface what this product actually offers). $returnDays = optional(\App\Genral::first())->return_in_days ?? 30; $hasWarranty = $warrantyLabel !== ''; $hasReturn = ($pro->return_avbl == '1'); $hasCancel = ($pro->cancel_avl == 1); $hasFreeShip = ($pro->free_shipping == 1); $hasCOD = ($pro->codcheck == 1); $tiles = []; if ($hasFreeShip) { $tiles[] = ['label' => __('Free Delivery'), 'sub' => __('On this product'), 'svg' => '', 'tone' => 'emerald']; } if ($hasReturn) { $tiles[] = ['label' => __('Easy Returns'), 'sub' => $returnDays . ' ' . __('day policy'), 'svg' => '', 'tone' => 'amber']; } if ($hasWarranty) { $tiles[] = ['label' => __('Warranty'), 'sub' => $warrantyLabel, 'svg' => '', 'tone' => 'brand']; } if ($hasCOD) { $tiles[] = ['label' => __('Cash on Delivery'), 'sub' => __('Available'), 'svg' => '', 'tone' => 'sky']; } if ($hasCancel) { $tiles[] = ['label' => __('Cancellable'), 'sub' => __('Order can be cancelled'), 'svg' => '', 'tone' => 'rose']; } $toneMap = [ 'emerald' => ['icon' => 'text-emerald-600', 'bg' => 'bg-emerald-50'], 'amber' => ['icon' => 'text-amber-600', 'bg' => 'bg-amber-50'], 'brand' => ['icon' => 'text-brand-600', 'bg' => 'bg-brand-50'], 'sky' => ['icon' => 'text-sky-600', 'bg' => 'bg-sky-50'], 'rose' => ['icon' => 'text-rose-500', 'bg' => 'bg-rose-50'], ]; @endphp {{-- Breadcrumbs --}}
{{ __('Inclusive of all taxes') }}
@endif{{ __('Standard shipping rates apply.') }}
@endif @if(isset($pro->store) && $pro->store) @php $storeLogoFile = $pro->store->store_logo ?? null; $storeLogoUrl = $storeLogoFile && file_exists(public_path('images/store/logo/' . $storeLogoFile)) ? url('images/store/logo/' . $storeLogoFile) : null; @endphp{{ $r->message ?? $r->review ?? '' }}
{{ __('No reviews yet. Be the first to review!') }}