@extends(auth()->check() ? 'user.layout' : 'user.public.layout')
@php
use App\Models\Product;
@endphp
@section('title', $product->name)
@push('head')
@endpush
@section('content')
@php
use App\Models\ProductFavorite;
$isLoggedIn = auth()->check();
$authUser = auth()->user();
$isReseller = $isLoggedIn && (int)($authUser->is_active ?? 0) === 1;
$firstImage = $product->images->first();
$allImages = $product->images->count() ? $product->images : collect([(object)['image_url' => asset('images/default-product.png')]]);
$ownDistrict = $setting->own_district ?? 'নিজ জেলা';
$isFavorite = $product->is_favorite ?? false;
$firstImageUrl = $firstImage ? $firstImage->image_url : asset('images/default-product.png');
$resellerMaxPrice = (float)($product->reseller_max_price ?? 0);
// Vendor Info
$vendor = $product->vendor ?? null;
$hasVendor = $vendor && $vendor->isApprovedVendor();
$descriptionHtml = (string) ($product->description ?: '
]*>(?:\s| |
)*<\/div>/iu', "\n", $descriptionForCopy);
$descriptionForCopy = preg_replace('/<\s*br\s*\/?\s*>/i', "\n", $descriptionForCopy);
$descriptionForCopy = preg_replace('/<\s*li[^>]*>/i', "\n• ", $descriptionForCopy);
$descriptionForCopy = preg_replace('/<\s*\/\s*li\s*>/i', '', $descriptionForCopy);
$descriptionForCopy = preg_replace('/<\s*\/\s*(p|div|section|article|blockquote|h[1-6])\s*>/i', "\n", $descriptionForCopy);
$descriptionForCopy = preg_replace('/<\s*(p|div|section|article|blockquote|h[1-6])[^>]*>/i', '', $descriptionForCopy);
$descriptionForCopy = preg_replace('/<\s*\/\s*(td|th)\s*>/i', "\t", $descriptionForCopy);
$descriptionForCopy = preg_replace('/<\s*\/\s*tr\s*>/i', "\n", $descriptionForCopy);
$descriptionForCopy = preg_replace('/<\s*\/\s*(ul|ol|table|thead|tbody)\s*>/i', "\n", $descriptionForCopy);
$descriptionForCopy = strip_tags($descriptionForCopy);
$descriptionForCopy = html_entity_decode($descriptionForCopy, ENT_QUOTES | ENT_HTML5, 'UTF-8');
$descriptionForCopy = str_replace("\xc2\xa0", ' ', $descriptionForCopy);
$descriptionForCopy = preg_replace("/\r\n|\r/u", "\n", $descriptionForCopy);
$descriptionForCopy = preg_replace("/[ \t]+\n/u", "\n", $descriptionForCopy);
$descriptionForCopy = preg_replace("/\n[ \t]+/u", "\n", $descriptionForCopy);
$descriptionLines = explode("\n", $descriptionForCopy);
$descriptionLines = array_map('trim', $descriptionLines);
$descriptionForCopy = implode("\n", $descriptionLines);
$descriptionForCopy = preg_replace("/\n{3,}/u", "\n\n", $descriptionForCopy);
$plainDescription = trim($descriptionForCopy);
if ($plainDescription === '') {
$plainDescription = 'কোনো বিস্তারিত বিবরণ নেই।';
}
$relatedQuery = Product::with(['images', 'category', 'subCategory', 'vendor'])
->where('id', '!=', $product->id)
->where('category_id', $product->category_id);
if (($setting->hold_action ?? null) === 'hide') {
$relatedQuery->where('is_hold', 0);
}
if (($setting->stock_out_action ?? null) === 'hide') {
$relatedQuery->where('stock', '>', 0);
}
$relatedProducts = $relatedQuery->latest()->take(8)->get();
foreach ($relatedProducts as $relatedProduct) {
$basePrice = $isReseller ? $relatedProduct->reseller_price : $relatedProduct->customer_price;
$discountAllowed = false;
if ($relatedProduct->has_discount && $relatedProduct->discount_percent) {
$discountAllowed = $isReseller
? in_array($relatedProduct->discount_for, ['reseller', 'both'])
: in_array($relatedProduct->discount_for, ['customer', 'both']);
}
$finalPrice = $discountAllowed
? $basePrice - (($basePrice * $relatedProduct->discount_percent) / 100)
: $basePrice;
$relatedProduct->display_price = [
'base' => $basePrice,
'final' => $finalPrice,
'has_discount' => $discountAllowed,
'discount_percent' => $discountAllowed ? $relatedProduct->discount_percent : null,
];
$relatedProduct->is_favorite = $isLoggedIn
? ProductFavorite::where('user_id', $authUser->id)->where('product_id', $relatedProduct->id)->exists()
: false;
$relatedProduct->is_order_off =
($relatedProduct->is_hold && ($setting->hold_action ?? null) === 'show_disable')
|| ($relatedProduct->stock <= 0 && ($setting->stock_out_action ?? null) === 'show_disable');
}
$whatsappText = "🛍️ প্রোডাক্ট ইনফো\n\n📌 নাম: {$product->name}\n🆔 কোড: {$product->product_code}\n💰 মূল্য: ৳" . number_format($product->display_price['final'], 0) . "\n\n📝 বিস্তারিত:\n{$plainDescription}\n\n🖼️ ছবি:\n{$firstImageUrl}";
@endphp
{{-- Product Card --}}
@if($product->images->count())
@foreach($product->images as $key => $image)
@endforeach
@endif
@if($isLoggedIn)
@endif
@if($product->is_order_off)
@else
@endif
@if($product->is_order_off)
@else
অর্ডার
@endif
কন্টাক্ট
{{-- Vendor Info Box --}}
@if($hasVendor)
@if($vendor->getStoreLogoUrl())
 }})
@else
@endif
{{ $vendor->store_name ?? $vendor->name }}
@if($vendor->store_is_active && $vendor->vendor_status === 'approved')
ভেন্ডর
@else
ভেন্ডর
@endif
শপ দেখুন
@endif
{{-- Product Info --}}
প্রোডাক্ট কোড: {{ $product->product_code ?? 'N/A' }}
ক্যাটাগরি: {{ $product->category->name ?? '-' }}
@if($product->subCategory)
/ {{ $product->subCategory->name }}
@endif
@if($isReseller)
পাইকারি মূল্য
৳{{ number_format($product->display_price['final'], 0) }}
@if($product->display_price['has_discount'])
৳{{ number_format($product->display_price['base'], 0) }}
{{ rtrim(rtrim($product->display_price['discount_percent'], '0'), '.') }}% OFF
@endif
সর্বোচ্চ বিক্রয় মূল্য
৳{{ number_format($resellerMaxPrice, 0) }}
@else
{{ $product->display_price['label'] }}
৳{{ number_format($product->display_price['final'], 0) }}
@if($product->display_price['has_discount'])
৳{{ number_format($product->display_price['base'], 0) }}
{{ rtrim(rtrim($product->display_price['discount_percent'], '0'), '.') }}% OFF
@endif
@endif
স্টক
{{ $product->stock > 0 ? $product->stock.' টি' : 'স্টক নেই' }}
ডেলিভারি টাইম
{{ $setting->delivery_time ?? '-' }}
@if(($setting->delivery_type ?? 'free') == 'paid')
{{ $ownDistrict }} এর ভিতরে
৳{{ number_format($setting->own_district_charge ?? 0, 0) }}
{{ $ownDistrict }} এর বাহিরে
৳{{ number_format($setting->other_district_charge ?? 0, 0) }}
@else
ডেলিভারি চার্জ
ফ্রি ডেলিভারি
@endif
@if($product->has_warranty)
ওয়ারেন্টি / গ্যারান্টি
{{ $product->warranty_text ?? 'আছে' }}
@endif
@if($product->has_size && is_array($product->sizes) && count($product->sizes))
সাইজ
@foreach($product->sizes as $size)
{{ $size }}
@endforeach
@endif
@if($product->has_color && is_array($product->colors) && count($product->colors))
কালার
@foreach($product->colors as $color)
{{ $color }}
@endforeach
@endif
{{-- Description --}}
{!! $product->description ?: '
কোনো বিস্তারিত বিবরণ নেই।
' !!}
{{-- Related Products --}}
{{-- Order Bar --}}
@if($product->is_order_off)
@else
এখনই অর্ডার করুন
@endif
@endsection