{{-- Product card: photo, name, brand and category, MRP and price (incl. GST), the pack to buy (a dropdown when the product has options, e.g. 1 kg / 5 kg / 25 kg), "View product" and a round "+" that adds it to the cart (the cart drawer script takes the form over). Prices follow the chosen pack via [data-card-variant]. --}} @props(['product']) @php $hasVariants = ! empty($product['has_variants']) && ! empty($product['variants']); $variants = $hasVariants ? collect($product['variants']) : collect(); $first = $hasVariants ? ($variants->first(fn ($v) => $v['stock'] > 0) ?? $variants->first()) : null; $price = (int) ($first['price'] ?? $product['price']); $mrp = (int) ($first['mrp'] ?? ($product['mrp'] ?? 0)); $off = $mrp > $price ? (int) round(($mrp - $price) / $mrp * 100) : 0; $stock = (int) ($first['stock'] ?? $product['stock']); $img = str_starts_with($product['image'], 'http') ? $product['image'] : asset($product['image']); $rupees = fn (int|float $v) => inr($v); // Indian grouping: ₹1,00,000 $details = (array) ($product['details'] ?? []); $pack = collect(['Pack', 'Bag', 'Weight', 'Size', 'Length', 'Pieces'])->map(fn ($k) => $details[$k] ?? null)->filter()->first() ?? ($details ? array_key_first($details).': '.reset($details) : null); $meta = collect([$product['brand'] ?? null, $product['category_name'] ?? null])->filter()->implode(' · '); $uid = 'v'.substr(md5(uniqid('', true)), 0, 10); // unique per card: a product can appear in several sections $inCart = isset($product['slug']) && collect(array_keys(app(\App\Modules\Cart\Services\CartService::class)->raw()))->contains(fn ($k) => $k === $product['slug'] || str_starts_with((string) $k, $product['slug'].'::')); $saved = isset($product['slug']) && app(\App\Modules\Cart\Services\WishlistService::class)->has($product['slug']); @endphp
class('pcard') }} data-card @isset($product['category']) data-cat="{{ $product['category'] }}" @endisset>
@isset($product['slug'])
@csrf
@endisset

{{ $product['name'] }}

@if ($meta){{ $meta }}@endif
{{ $rupees($price) }} incl. GST
@isset($product['slug'])
@csrf @if ($hasVariants) @php $optName = implode(' / ', (array) ($product['option_names'] ?? [])) ?: 'Option'; @endphp @else
{{ $pack ?: 'Single pack' }}
@endif
View product
@endisset