2023-06-11 12:14:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Themes\Storefront\Http\ViewComposers;
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
use Illuminate\View\View;
|
2023-06-11 12:14:03 +00:00
|
|
|
use Themes\Storefront\Banner;
|
|
|
|
use Themes\Storefront\Feature;
|
|
|
|
use Modules\Brand\Entities\Brand;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Modules\Slider\Entities\Slider;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Modules\Category\Entities\Category;
|
|
|
|
|
|
|
|
class HomePageComposer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bind data to the view.
|
|
|
|
*
|
2023-12-03 14:07:47 +00:00
|
|
|
* @param View $view
|
|
|
|
*
|
2023-06-11 12:14:03 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function compose($view)
|
|
|
|
{
|
|
|
|
$view->with([
|
|
|
|
'slider' => Slider::findWithSlides(setting('storefront_slider')),
|
|
|
|
'sliderBanners' => Banner::getSliderBanners(),
|
|
|
|
'features' => Feature::all(),
|
|
|
|
'featuredCategories' => $this->featuredCategoriesSection(),
|
|
|
|
'threeColumnFullWidthBanners' => $this->threeColumnFullWidthBanners(),
|
|
|
|
'productTabsOne' => $this->productTabsOne(),
|
|
|
|
'topBrands' => $this->topBrands(),
|
|
|
|
'flashSaleAndVerticalProducts' => $this->flashSaleAndVerticalProducts(),
|
|
|
|
'twoColumnBanners' => $this->twoColumnBanners(),
|
|
|
|
'productGrid' => $this->productGrid(),
|
|
|
|
'threeColumnBanners' => $this->threeColumnBanners(),
|
|
|
|
'tabProductsTwo' => $this->tabProductsTwo(),
|
|
|
|
'oneColumnBanner' => $this->oneColumnBanner(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function featuredCategoriesSection()
|
|
|
|
{
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!setting('storefront_featured_categories_section_enabled')) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'title' => setting('storefront_featured_categories_section_title'),
|
|
|
|
'subtitle' => setting('storefront_featured_categories_section_subtitle'),
|
|
|
|
'categories' => $this->getFeaturedCategories(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function getFeaturedCategories()
|
|
|
|
{
|
|
|
|
$categoryIds = Collection::times(6, function ($number) {
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!is_null(setting("storefront_featured_categories_section_category_{$number}_product_type"))) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return setting("storefront_featured_categories_section_category_{$number}_category_id");
|
|
|
|
}
|
|
|
|
})->filter();
|
|
|
|
|
|
|
|
return Category::with('files')
|
|
|
|
->whereIn('id', $categoryIds)
|
|
|
|
->when($categoryIds->isNotEmpty(), function ($query) use ($categoryIds) {
|
|
|
|
$query->orderByRaw("FIELD(id, {$categoryIds->filter()->implode(',')})");
|
|
|
|
})
|
|
|
|
->get()
|
|
|
|
->map(function ($category) {
|
|
|
|
return [
|
|
|
|
'name' => $category->name,
|
|
|
|
'logo' => $category->logo,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function threeColumnFullWidthBanners()
|
|
|
|
{
|
|
|
|
if (setting('storefront_three_column_full_width_banners_enabled')) {
|
|
|
|
return Banner::getThreeColumnFullWidthBanners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function productTabsOne()
|
|
|
|
{
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!setting('storefront_product_tabs_1_section_enabled')) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Collection::times(4, function ($number) {
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!is_null(setting("storefront_product_tabs_1_section_tab_{$number}_product_type"))) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return setting("storefront_product_tabs_1_section_tab_{$number}_title");
|
|
|
|
}
|
|
|
|
})->filter();
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function topBrands()
|
|
|
|
{
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!setting('storefront_top_brands_section_enabled')) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return collect();
|
|
|
|
}
|
|
|
|
|
|
|
|
$topBrandIds = setting('storefront_top_brands', []);
|
|
|
|
|
|
|
|
return Cache::rememberForever(md5('storefront_top_brands:' . serialize($topBrandIds)), function () use ($topBrandIds) {
|
|
|
|
return Brand::with('files')
|
|
|
|
->whereIn('id', $topBrandIds)
|
2023-12-03 14:07:47 +00:00
|
|
|
->when(!empty($topBrandIds), function ($query) use ($topBrandIds) {
|
2023-06-11 12:14:03 +00:00
|
|
|
$topBrandIdsString = collect($topBrandIds)->filter()->implode(',');
|
|
|
|
|
|
|
|
$query->orderByRaw("FIELD(id, {$topBrandIdsString})");
|
|
|
|
})
|
|
|
|
->get()
|
|
|
|
->map(function (Brand $brand) {
|
|
|
|
return [
|
|
|
|
'url' => $brand->url(),
|
|
|
|
'logo' => $brand->getLogoAttribute(),
|
|
|
|
];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function flashSaleAndVerticalProducts()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'flash_sale_title' => setting('storefront_flash_sale_title'),
|
|
|
|
'vertical_products_1_title' => setting('storefront_vertical_products_1_title'),
|
|
|
|
'vertical_products_2_title' => setting('storefront_vertical_products_2_title'),
|
|
|
|
'vertical_products_3_title' => setting('storefront_vertical_products_3_title'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function twoColumnBanners()
|
|
|
|
{
|
|
|
|
if (setting('storefront_two_column_banners_enabled')) {
|
|
|
|
return Banner::getTwoColumnBanners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function productGrid()
|
|
|
|
{
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!setting('storefront_product_grid_section_enabled')) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Collection::times(4, function ($number) {
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!is_null(setting("storefront_product_grid_section_tab_{$number}_product_type"))) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return setting("storefront_product_grid_section_tab_{$number}_title");
|
|
|
|
}
|
|
|
|
})->filter();
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function threeColumnBanners()
|
|
|
|
{
|
|
|
|
if (setting('storefront_three_column_banners_enabled')) {
|
|
|
|
return Banner::getThreeColumnBanners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function tabProductsTwo()
|
|
|
|
{
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!setting('storefront_product_tabs_2_section_enabled')) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tabs = Collection::times(4, function ($number) {
|
2023-12-03 14:07:47 +00:00
|
|
|
if (!is_null(setting("storefront_product_tabs_2_section_tab_{$number}_product_type"))) {
|
2023-06-11 12:14:03 +00:00
|
|
|
return setting("storefront_product_tabs_2_section_tab_{$number}_title");
|
|
|
|
}
|
|
|
|
})->filter();
|
|
|
|
|
|
|
|
return [
|
|
|
|
'title' => setting('storefront_product_tabs_2_section_title'),
|
|
|
|
'tabs' => $tabs,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-12-03 14:07:47 +00:00
|
|
|
|
2023-06-11 12:14:03 +00:00
|
|
|
private function oneColumnBanner()
|
|
|
|
{
|
|
|
|
if (setting('storefront_one_column_banner_enabled')) {
|
|
|
|
return Banner::getOneColumnBanner();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|