@extends('ecommerce::layout.store-layout')
{{-- @section bodies are evaluated BEFORE the parent layout runs, so anything the
sections need must be resolved here, not in store-layout. --}}
@php
$currentLocale = $currentLocale ?? app()->getLocale();
$isRTL = $isRTL ?? in_array($currentLocale, ['ar', 'he', 'fa', 'ur'], true);
@endphp
@section('title', __('ecommerce::ecommerce.home'))
@section('active-nav', 'home')
@section('page-styles')
@endsection
@section('content')
@php
$localized = static function ($value, $fallback = '') use ($currentLocale) {
if (is_array($value)) {
return $value[$currentLocale] ?? ($value['en'] ?? (reset($value) ?? $fallback));
}
return $value ?: $fallback;
};
$image = static function ($value, $fallback = 'assets/ecommerce/images/slider/4.webp') {
return $value ?: asset($fallback);
};
$bannerBackgroundStyle = static function ($banner, $fallback = 'assets/ecommerce/images/slider/4.webp') use ($image) {
$desktop = $image($banner->desktop_image_url ?? ($banner->image_desktop ?? null), $fallback);
$tablet = $image($banner->tablet_image_url ?? null, $desktop);
$mobile = $image($banner->mobile_image_url ?? null, $desktop);
return "--ad-image-desktop:url('{$desktop}');--ad-image-tablet:url('{$tablet}');--ad-image-mobile:url('{$mobile}')";
};
$products = static function ($items) {
return collect($items ?? [])
->filter()
->values();
};
$renderProduct = static function ($product) use ($image, $localized) {
$title = $localized($product->title ?? null, __('ecommerce::ecommerce.product_label'));
$productImage = $image($product->image_path ?? ($product->image ?? null));
$price = (float) ($product->default_price ?? ($product->price ?? 0));
return compact('title', 'productImage', 'price');
};
@endphp
@php
$heroSlides = collect($mainSlider ?? [])
->map(function ($slide) {
if (is_array($slide)) {
$slide = (object) $slide;
}
$defaultImg = asset('assets/ecommerce/images/slider/4.webp');
$resolveImage = function (string $device) use ($slide) {
$image = method_exists($slide, 'getImageUrl')
? $slide->getImageUrl($device)
: ($slide->{$device . '_image_url'} ??
data_get($slide, "content.images.{$device}") ??
($slide->{'image_' . $device} ?? null));
if ($image && !filter_var($image, FILTER_VALIDATE_URL) && !str_starts_with($image, '/') && file_exists(public_path($image))) {
$image = asset($image);
}
return $image ?: null;
};
$slide->resolved_images = [
'desktop' => $resolveImage('desktop'),
'tablet' => $resolveImage('tablet'),
'mobile' => $resolveImage('mobile'),
];
$slide->resolved_image = $slide->resolved_images['desktop']
?: $slide->resolved_images['tablet']
?: $slide->resolved_images['mobile']
?: $defaultImg;
return $slide;
})
->values();
if ($heroSlides->isEmpty()) {
$heroSlides = collect([
(object) [
'localized_title' => __('ecommerce::ecommerce.home_hero_title', [], $currentLocale),
'localized_subtitle' => __('ecommerce::ecommerce.home_hero_subtitle', [], $currentLocale),
'click_url' => '#products',
'resolved_image' => asset('assets/ecommerce/images/slider/4.webp'),
],
]);
}
@endphp
@if ($heroSlides->isNotEmpty())
@foreach ($heroSlides as $idx => $slide)
@php
$slideCount = $heroSlides->count();
$galleryIndexes = array_values(
array_unique([$idx, ($idx + 1) % $slideCount, ($idx + 2) % $slideCount]),
);
$buttonText = data_get($slide, "click_action.button_text.{$currentLocale}");
@endphp
@endforeach
@endif
@php
$productSections = collect([
[
'products' => $bestSellers ?? [],
'title' => __('ecommerce::ecommerce.best_sellers'),
'id' => 'best-sellers',
'collection' => 'best-sellers',
],
[
'products' => $featuredProducts ?? [],
'title' => __('ecommerce::ecommerce.featured_products'),
'id' => 'featured-products',
'collection' => 'featured-products',
],
[
'products' => $newProducts ?? [],
'title' => __('ecommerce::ecommerce.new_products'),
'id' => 'new-products',
'collection' => 'new-products',
],
[
'products' => $exclusiveProducts ?? [],
'title' => __('ecommerce::ecommerce.exclusive_collections'),
'id' => 'exclusive-products',
'collection' => 'exclusive-products',
],
])
->filter(fn($section) => collect($section['products'])->isNotEmpty())
->values();
$midProductBanner = collect($largeBanner ?? [])->first();
$bannerAfterSection = min(2, $productSections->count());
@endphp
@foreach ($productSections as $section)
@if ($midProductBanner && $loop->iteration === $bannerAfterSection)
@endif
@endforeach