first upload all files

This commit is contained in:
NW
2023-06-11 13:14:03 +01:00
parent f14dbc52b5
commit c08b36d1b6
1705 changed files with 106852 additions and 0 deletions

View File

@@ -0,0 +1,182 @@
<?php
namespace Themes\Storefront\Http\ViewComposers;
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.
*
* @param \Illuminate\View\View $view
* @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(),
]);
}
private function featuredCategoriesSection()
{
if (! setting('storefront_featured_categories_section_enabled')) {
return;
}
return [
'title' => setting('storefront_featured_categories_section_title'),
'subtitle' => setting('storefront_featured_categories_section_subtitle'),
'categories' => $this->getFeaturedCategories(),
];
}
private function getFeaturedCategories()
{
$categoryIds = Collection::times(6, function ($number) {
if (! is_null(setting("storefront_featured_categories_section_category_{$number}_product_type"))) {
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,
];
});
}
private function threeColumnFullWidthBanners()
{
if (setting('storefront_three_column_full_width_banners_enabled')) {
return Banner::getThreeColumnFullWidthBanners();
}
}
private function productTabsOne()
{
if (! setting('storefront_product_tabs_1_section_enabled')) {
return;
}
return Collection::times(4, function ($number) {
if (! is_null(setting("storefront_product_tabs_1_section_tab_{$number}_product_type"))) {
return setting("storefront_product_tabs_1_section_tab_{$number}_title");
}
})->filter();
}
private function topBrands()
{
if (! setting('storefront_top_brands_section_enabled')) {
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)
->when(! empty($topBrandIds), function ($query) use ($topBrandIds) {
$topBrandIdsString = collect($topBrandIds)->filter()->implode(',');
$query->orderByRaw("FIELD(id, {$topBrandIdsString})");
})
->get()
->map(function (Brand $brand) {
return [
'url' => $brand->url(),
'logo' => $brand->getLogoAttribute(),
];
});
});
}
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'),
];
}
private function twoColumnBanners()
{
if (setting('storefront_two_column_banners_enabled')) {
return Banner::getTwoColumnBanners();
}
}
private function productGrid()
{
if (! setting('storefront_product_grid_section_enabled')) {
return;
}
return Collection::times(4, function ($number) {
if (! is_null(setting("storefront_product_grid_section_tab_{$number}_product_type"))) {
return setting("storefront_product_grid_section_tab_{$number}_title");
}
})->filter();
}
private function threeColumnBanners()
{
if (setting('storefront_three_column_banners_enabled')) {
return Banner::getThreeColumnBanners();
}
}
private function tabProductsTwo()
{
if (! setting('storefront_product_tabs_2_section_enabled')) {
return;
}
$tabs = Collection::times(4, function ($number) {
if (! is_null(setting("storefront_product_tabs_2_section_tab_{$number}_product_type"))) {
return setting("storefront_product_tabs_2_section_tab_{$number}_title");
}
})->filter();
return [
'title' => setting('storefront_product_tabs_2_section_title'),
'tabs' => $tabs,
];
}
private function oneColumnBanner()
{
if (setting('storefront_one_column_banner_enabled')) {
return Banner::getOneColumnBanner();
}
}
}

View File

@@ -0,0 +1,209 @@
<?php
namespace Themes\Storefront\Http\ViewComposers;
use Mexitek\PHPColors\Color;
use Modules\Compare\Compare;
use Spatie\SchemaOrg\Schema;
use Modules\Tag\Entities\Tag;
use Modules\Cart\Facades\Cart;
use Modules\Menu\Entities\Menu;
use Modules\Page\Entities\Page;
use Modules\Media\Entities\File;
use Modules\Menu\MegaMenu\MegaMenu;
use Illuminate\Support\Facades\Cache;
use Modules\Category\Entities\Category;
use Modules\Product\Entities\SearchTerm;
class LayoutComposer
{
/**
* @var \Modules\Compare\Compare
*/
private $compare;
/**
* Create a new view composer instance.
*
* @param \Modules\Compare\Compare $compare
*/
public function __construct(Compare $compare)
{
$this->compare = $compare;
}
/**
* Bind data to the view.
*
* @param \Illuminate\View\View $view
* @return void
*/
public function compose($view)
{
$view->with([
'themeColor' => $this->getThemeColor(),
'compareCount' => $this->compare->count(),
'favicon' => $this->getFavicon(),
'logo' => $this->getHeaderLogo(),
'newsletterBgImage' => $this->getNewsletterBgImage(),
'privacyPageUrl' => $this->getPrivacyPageUrl(),
'categories' => $this->getCategories(),
'mostSearchedKeywords' => $this->getMostSearchedKeywords(),
'primaryMenu' => $this->getPrimaryMenu(),
'categoryMenu' => $this->getCategoryMenu(),
'cart' => $this->getCart(),
'wishlist' => $this->getWishlist(),
'compareList' => $this->compare->list(),
'footerMenuOne' => $this->getFooterMenuOne(),
'footerMenuTwo' => $this->getFooterMenuTwo(),
'footerTags' => $this->getFooterTags(),
'copyrightText' => $this->getCopyrightText(),
'acceptedPaymentMethodsImage' => $this->getAcceptedPaymentMethodsImage(),
'schemaMarkup' => $this->getSchemaMarkup(),
]);
}
private function getThemeColor()
{
try {
return new Color(storefront_theme_color());
} catch (\Exception $e) {
return new Color('#0068e1');
}
}
private function getFavicon()
{
return $this->getMedia(setting('storefront_favicon'))->path;
}
private function getHeaderLogo()
{
return $this->getMedia(setting('storefront_header_logo'))->path;
}
private function getNewsletterBgImage()
{
return $this->getMedia(setting('storefront_newsletter_bg_image'))->path;
}
private function getMedia($fileId)
{
return Cache::rememberForever(md5("files.{$fileId}"), function () use ($fileId) {
return File::findOrNew($fileId);
});
}
private function getPrivacyPageUrl()
{
return Cache::tags('settings')->rememberForever('privacy_page_url', function () {
return Page::urlForPage(setting('storefront_privacy_page'));
});
}
private function getCategories()
{
return Category::searchable();
}
private function getMostSearchedKeywords()
{
return Cache::remember('most_searched_keywords', now()->addHour(), function () {
return SearchTerm::select('term')->orderByDesc('hits')->take(5)->pluck('term');
});
}
private function getPrimaryMenu()
{
return new MegaMenu(setting('storefront_primary_menu'));
}
private function getCategoryMenu()
{
return new MegaMenu(setting('storefront_category_menu'));
}
private function getCart()
{
return Cart::instance();
}
private function getWishlist()
{
if (auth()->guest()) {
return collect();
}
return auth()->user()->wishlist()->pluck('product_id');
}
private function getFooterMenuOne()
{
return $this->getFooterMenu(setting('storefront_footer_menu_one'));
}
private function getFooterMenuTwo()
{
return $this->getFooterMenu(setting('storefront_footer_menu_two'));
}
private function getFooterMenu($menuId)
{
return Cache::tags(['menu_items', 'categories', 'pages', 'settings'])
->rememberForever(md5("storefront_footer_menu.{$menuId}:" . locale()), function () use ($menuId) {
return Menu::for($menuId);
});
}
private function getFooterTags()
{
$tagIds = setting('storefront_footer_tags', []);
return Cache::tags(['tags', 'settings'])
->rememberForever(
md5('storefront_footer_tags:' . serialize($tagIds) . ':' . locale()),
$this->footerTagsCallback($tagIds)
);
}
public function footerTagsCallback($tagIds)
{
return function () use ($tagIds) {
return Tag::whereIn('id', $tagIds)
->when(! empty($tagIds), function ($query) use ($tagIds) {
$tagIdsString = collect($tagIds)->filter()->implode(',');
$query->orderByRaw("FIELD(id, {$tagIdsString})");
})
->get();
};
}
private function getCopyrightText()
{
return strtr(setting('storefront_copyright_text'), [
'{{ store_url }}' => route('home'),
'{{ store_name }}' => setting('store_name'),
'{{ year }}' => date('Y'),
]);
}
private function getAcceptedPaymentMethodsImage()
{
return $this->getMedia(setting('storefront_accepted_payment_methods_image'));
}
private function getSchemaMarkup()
{
return Schema::webSite()
->url(route('home'))
->potentialAction($this->searchActionSchema());
}
private function searchActionSchema()
{
return Schema::searchAction()
->target(route('products.index') . '?query={search_term_string}')
->setProperty('query-input', 'required name=search_term_string');
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Themes\Storefront\Http\ViewComposers;
use Modules\Support\Money;
use Modules\Product\Entities\Product;
use Modules\Category\Entities\Category;
class ProductIndexPageComposer
{
/**
* Bind data to the view.
*
* @param \Illuminate\View\View $view
* @return void
*/
public function compose($view)
{
$view->with([
'categories' => $this->categories(),
'maxPrice' => $this->maxPrice(),
'latestProducts' => $this->latestProducts(),
]);
}
private function categories()
{
return Category::tree();
}
private function maxPrice()
{
return Money::inDefaultCurrency(Product::max('selling_price'))
->convertToCurrentCurrency()
->ceil()
->amount();
}
private function latestProducts()
{
return Product::forCard()->take(5)->latest()->get()->map->clean();
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace Themes\Storefront\Http\ViewComposers;
use Illuminate\View\View;
use Spatie\SchemaOrg\Schema;
use Themes\Storefront\Banner;
use Themes\Storefront\Feature;
use Illuminate\Support\Collection;
use Modules\Product\Entities\Product;
use Spatie\SchemaOrg\ItemAvailability;
class ProductShowPageComposer
{
/**
* Bind data to the view.
*
* @param \Illuminate\View\View $view
* @return void
*/
public function compose(View $view)
{
$product = $view->getData()['product'];
$view->with([
'features' => Feature::all(),
'banner' => Banner::getProductPageBanner(),
'productSchemaMarkup' => $this->schemaMarkup($product),
'categoryBreadcrumb' => $this->getCategoryBreadCrumb($product->categories->nest()),
]);
}
private function schemaMarkup(Product $product)
{
return Schema::product()
->name($product->name)
->sku($product->sku)
->url($product->url())
->image($product->base_image->path)
->brand($this->brandSchema($product))
->description($product->short_description)
->aggregateRating($this->aggregateRatingSchema($product))
->offers($this->offersSchema($product));
}
private function brandSchema(Product $product)
{
return Schema::brand()->name($product->brand->name);
}
private function aggregateRatingSchema(Product $product)
{
return Schema::aggregateRating()
->ratingValue($product->reviews()->avg('rating'))
->ratingCount($product->reviews()->count());
}
private function offersSchema(Product $product)
{
return Schema::offer()
->price($product->selling_price->convertToCurrentCurrency()->amount())
->priceCurrency(currency())
->availability($product->isInStock() ? ItemAvailability::InStock : ItemAvailability::OutOfStock)
->url($product->url());
}
private function getCategoryBreadCrumb(Collection $categories)
{
$breadcrumb = '';
foreach ($categories as $category) {
$breadcrumb .= "<li><a href='{$category->url()}'>{$category->name}</a></li>";
if ($category->items->isNotEmpty()) {
$breadcrumb .= $this->getCategoryBreadCrumb($category->items);
}
}
return $breadcrumb;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Themes\Storefront\Http\ViewComposers;
use Modules\Category\Entities\Category;
class StorefrontTabsComposer
{
/**
* Bind data to the view.
*
* @param \Illuminate\View\View $view
* @return void
*/
public function compose($view)
{
$view->with([
'categories' => $this->getCategories(),
]);
}
private function getCategories()
{
return ['' => trans('admin::admin.form.please_select')] + Category::treeList();
}
}