@forelse($products as $product)
@php
// Image Logic
$imagePath = $product->variations->whereNotNull('image_path')->first()?->image_path
?? $product->images->first()?->image_path;
$imageUrl = 'https://placehold.co/400?text=No+Image';
if ($imagePath) {
// Strip any leading 'public/' or 'storage/' from the path from DB to avoid double prefixes
$cleanPath = str_replace(['public/', 'storage/'], '', $imagePath);
$imageUrl = \Illuminate\Support\Str::startsWith($imagePath, 'http') ? $imagePath : \Illuminate\Support\Facades\Storage::url($cleanPath);
}
// Prepare product object for JS
$productData = [
'name' => $product->name,
'category' => $product->category->name ?? 'Uncategorized',
'image_url' => $imageUrl,
'mrp' => number_format($product->mrp, 0),
'sp' => number_format($product->sp, 0),
'reseller_price' => number_format($product->reseller_price ?: ($product->sp ?: $product->mrp), 0),
'short_description' => $product->short_description ?? 'No short description available.',
'description' => $product->description ?? 'No details available.',
'unit' => $product->unit ?? 'N/A',
'country_of_origin' => $product->country_of_origin ?? 'N/A',
'stock' => $product->stock ?? 0,
];
@endphp
₹{{ number_format($product->reseller_price ?: ($product->sp ?: $product->mrp), 0) }}
{{ $product->name }}
{{ $product->category->name }}
MRP: ₹{{ number_format($product->mrp, 0) }}
SP: ₹{{ number_format($product->sp, 0) }}
@empty
No products found matching your search.
@endforelse