@php use Botble\Base\Facades\BaseHelper; use Botble\Ecommerce\Facades\EcommerceHelper; use Botble\Media\Facades\RvMedia; /** * Mirrors html/home-cosmetic.html §6 (lines 2090-2316): `banner-product-single * style-2 section-image-zoom` and html/home-headphone.html §8 (lines 2969-3276): * `banner-product-single style-4 section-image-zoom flat-spacing` — the layout * is identical, only the wrapper modifier class differs (`style-2` vs `style-4`), * controlled by the `banner_modifier` knob. * * LEFT vertical thumbnail strip (`product-thumbs-slider * style-row row_left`, main swiper + vertical thumbs) + RIGHT info panel: * [category tag] [name] [stars + reviews] [Best-seller badge + urgency] * [price + old + -%] [Size buttons] [Quantity + Add to cart/wishlist/compare] * [Buy It Now] [View Full] * * Distinct from `style-2-detail` (slim HomePetCare, no thumb strip) and * `style-3-pdp` (HomeSport `-v2`, SKU/share/size-guide extras). * * Shortcode attributes (all optional, safe fallbacks to $product): * product_id required — resolved by the parent index partial * featured_category category tag (default: product's first category, else "Shop") * featured_name display name (default: $product->name) * featured_price sale price (default: $product front sale/price) * featured_old_price strikethrough price (default: $product->price when on sale) * featured_sale_percent badge -% (default: computed from prices) * reviews_count rating badge count (0 = hide the rating row) * urgency_text "Selling fast! ..." — empty = hide * badge_text "Best seller" pre-order badge — empty = hide * size_options CSV "Label|price,Label|price" (e.g. "30ml|39.99,100ml|59.99") * default_size_index 0-based active index (default 0) * show_view_full yes/no "View Full" link (default yes) * banner_modifier wrapper modifier class — 'style-2' (default) or * 'style-4' (home-headphone §8). Anything else falls * back to 'style-2'. * * @var \Botble\Shortcode\Compilers\Shortcode $shortcode * @var \Botble\Ecommerce\Models\Product|null $product */ $bannerModifier = trim((string) ($shortcode->banner_modifier ?? '')); $bannerModifier = in_array($bannerModifier, ['style-2', 'style-4'], true) ? $bannerModifier : 'style-2'; $detailTag = trim((string) ($shortcode->featured_category ?? '')); if ($detailTag === '' && $product) { $detailTag = (string) ($product->categories?->first()?->name ?? __('Shop')); } $detailName = trim((string) ($shortcode->featured_name ?? '')) ?: ($product?->name ?? ''); $reviewsCount = (int) ($shortcode->reviews_count ?? 0); $urgencyText = trim((string) ($shortcode->urgency_text ?? '')); $badgeText = trim((string) ($shortcode->badge_text ?? '')); $showViewFull = filter_var($shortcode->show_view_full ?? 'yes', FILTER_VALIDATE_BOOLEAN); // Price — explicit featured_* overrides win, else fall back to the product. $currentPrice = $shortcode->featured_price ?? null; $oldPrice = $shortcode->featured_old_price ?? null; $salePercent = (int) ($shortcode->featured_sale_percent ?? 0); if ($currentPrice === null && $product) { $currentPrice = $product->front_sale_price_with_taxes ?? $product->front_sale_price ?? $product->price; if ($product->front_sale_price !== null && $product->price > 0 && (float) $product->front_sale_price < (float) $product->price) { $oldPrice = $product->price; $salePercent = (int) round((1 - ((float) $product->front_sale_price / (float) $product->price)) * 100); } } $isOnSale = $oldPrice !== null && (float) $oldPrice > (float) $currentPrice; // Parse size options CSV — each entry "Label|price" or just "Label". $sizeOptions = []; foreach (explode(',', (string) ($shortcode->size_options ?? '')) as $entry) { $entry = trim($entry); if ($entry === '') continue; [$label, $price] = array_pad(explode('|', $entry, 2), 2, null); $sizeOptions[] = ['label' => trim((string) $label), 'price' => trim((string) $price)]; } $defaultSizeIdx = $sizeOptions ? max(0, min(count($sizeOptions) - 1, (int) ($shortcode->default_size_index ?? 0))) : 0; // Gallery — product images, fall back to the single main image. $galleryImages = []; if ($product) { $galleryImages = collect($product->images ?? []) ->filter(fn ($img) => is_string($img) && trim($img) !== '') ->values() ->all(); if (empty($galleryImages) && $product->image) { $galleryImages = [$product->image]; } } @endphp @if ($product) @endif