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,34 @@
<?php
namespace Themes\Storefront\Http\Controllers\Admin;
use Modules\Admin\Ui\Facades\TabManager;
use Themes\Storefront\Http\Requests\SaveStorefrontRequest;
class StorefrontController
{
/**
* Show the form for editing the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function edit()
{
$settings = setting()->all();
$tabs = TabManager::get('storefront');
return view('admin.storefront.edit', compact('settings', 'tabs'));
}
/**
* Update the specified resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function update(SaveStorefrontRequest $request)
{
setting($request->except('_token', '_method'));
return back()->withSuccess(trans('admin::messages.resource_saved', ['resource' => trans('setting::settings.settings')]));
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Themes\Storefront\Http\Controllers;
class CookieBarController
{
public function destroy()
{
$cookie = cookie()->forever('show_cookie_bar', false);
return response('')->withCookie($cookie);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Themes\Storefront\Http\Controllers;
class FeaturedCategoryProductController extends ProductIndexController
{
/**
* Display a listing of the resource.
*
* @param int $categoryNumber
* @return \Illuminate\Http\Response
*/
public function index($categoryNumber)
{
return $this->getProducts("storefront_featured_categories_section_category_{$categoryNumber}");
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Themes\Storefront\Http\Controllers;
use Modules\FlashSale\Entities\FlashSale;
class FlashSaleProductController
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return FlashSale::active()->products->map->clean();
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Themes\Storefront\Http\Controllers;
class NewsletterPopup
{
public function store()
{
$cookie = cookie()->forever('show_newsletter_popup', true);
return response('')->withCookie($cookie);
}
public function destroy()
{
$cookie = cookie()->forever('show_newsletter_popup', false);
return response('')->withCookie($cookie);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Themes\Storefront\Http\Controllers;
class ProductGridController extends ProductIndexController
{
/**
* Display a listing of the resource.
*
* @param int $tabNumber
* @return \Illuminate\Http\Response
*/
public function index($tabNumber)
{
return $this->getProducts("storefront_product_grid_section_tab_{$tabNumber}");
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace Themes\Storefront\Http\Controllers;
use Illuminate\Support\Collection;
use Modules\Product\RecentlyViewed;
use Modules\Product\Entities\Product;
use Modules\Category\Entities\Category;
class ProductIndexController
{
private $recentlyViewed;
public function __construct(RecentlyViewed $recentlyViewed)
{
$this->recentlyViewed = $recentlyViewed;
}
protected function getProducts($settingPrefix)
{
$type = setting("{$settingPrefix}_product_type", 'custom_products');
$limit = setting("{$settingPrefix}_products_limit");
if ($type === 'category_products') {
return $this->categoryProducts($settingPrefix,$limit);
}
if ($type === 'recently_viewed_products') {
return $this->recentlyViewedProducts($limit);
}
return Product::forCard()
->when($type === 'latest_products', $this->latestProductsCallback($limit))
->when($type === 'custom_products', $this->customProductsCallback($settingPrefix))
->get()
->map
->clean();
}
private function categoryProducts($settingPrefix,$limit)
{
return Category::findOrNew(setting("{$settingPrefix}_category_id"))
->products()
->forCard()
->take($limit)
->get();
}
private function recentlyViewedProducts($limit)
{
return collect($this->recentlyViewed->products())
->reverse()
->when(! is_null($limit), function (Collection $products) use ($limit) {
return $products->take($limit);
})
->values();
}
private function latestProductsCallback($limit)
{
return function ($query) use ($limit) {
$query->latest()
->when(! is_null($limit), function ($q) use ($limit) {
$q->limit($limit);
});
};
}
private function customProductsCallback($settingPrefix)
{
return function ($query) use ($settingPrefix) {
$productIds = setting("{$settingPrefix}_products", []);
$query->whereIn('id', $productIds)
->when(! empty($productIds), function ($q) use ($productIds) {
$productIdsString = collect($productIds)->filter()->implode(',');
$q->orderByRaw("FIELD(id, {$productIdsString})");
});
};
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Themes\Storefront\Http\Controllers;
class TabProductController extends ProductIndexController
{
/**
* Display a listing of the resource.
*
* @param int $sectionNumber
* @param int $tabNumber
* @return \Illuminate\Http\Response
*/
public function index($sectionNumber, $tabNumber)
{
return $this->getProducts("storefront_product_tabs_{$sectionNumber}_section_tab_{$tabNumber}");
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Themes\Storefront\Http\Controllers;
class VerticalProductController extends ProductIndexController
{
/**
* Display a listing of the resource.
*
* @param int $columnNumber
* @return \Illuminate\Http\Response
*/
public function index($columnNumber)
{
return $this->getProducts("storefront_vertical_products_{$columnNumber}");
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Themes\Storefront\Http\Requests;
use Modules\Core\Http\Requests\Request;
class SaveStorefrontRequest extends Request
{
/**
* Array of attributes that should be merged with null
* if attribute is not found in the current request.
*
* @var array
*/
private $shouldCheck = [
'storefront_footer_tags',
'storefront_featured_categories_section_category_1_products',
'storefront_featured_categories_section_category_2_products',
'storefront_featured_categories_section_category_3_products',
'storefront_featured_categories_section_category_4_products',
'storefront_featured_categories_section_category_5_products',
'storefront_featured_categories_section_category_6_products',
'storefront_product_tabs_1_section_tab_1_products',
'storefront_product_tabs_1_section_tab_2_products',
'storefront_product_tabs_1_section_tab_3_products',
'storefront_product_tabs_1_section_tab_4_products',
'storefront_top_brands',
'storefront_vertical_products_1_products',
'storefront_vertical_products_2_products',
'storefront_vertical_products_3_products',
'storefront_product_grid_section_tab_1_products',
'storefront_product_grid_section_tab_2_products',
'storefront_product_grid_section_tab_3_products',
'storefront_product_grid_section_tab_4_products',
'storefront_product_tabs_2_section_tab_1_products',
'storefront_product_tabs_2_section_tab_2_products',
'storefront_product_tabs_2_section_tab_3_products',
'storefront_product_tabs_2_section_tab_4_products',
];
/**
* Get data to be validated from the request.
*
* @return array
*/
public function validationData()
{
foreach ($this->shouldCheck as $attribute) {
if (! $this->has($attribute)) {
$this->merge([$attribute => null]);
}
}
return $this->all();
}
}

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();
}
}