fix bug and optimize
This commit is contained in:
parent
a0d952633f
commit
e984b1b672
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use DB;
|
||||||
|
|
||||||
class HomeController extends Controller
|
class HomeController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -16,6 +17,13 @@ class HomeController extends Controller
|
||||||
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
return view('home.grocery');
|
|
||||||
|
|
||||||
|
DB::listen(function ($query) {
|
||||||
|
logger($query->sql);
|
||||||
|
logger($query->bindings);
|
||||||
|
logger($query->time);
|
||||||
|
});
|
||||||
|
return view('home.grocery');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,8 @@ class Items extends Model
|
||||||
return $this->hasOne(ItemReference::class, 'item_id')
|
return $this->hasOne(ItemReference::class, 'item_id')
|
||||||
->where(function ($query) {
|
->where(function ($query) {
|
||||||
$query->whereNull('item_variant_id')->orWhere('item_variant_id', 0);
|
$query->whereNull('item_variant_id')->orWhere('item_variant_id', 0);
|
||||||
});
|
})
|
||||||
|
->with(['item','itemVariant']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function variants()
|
public function variants()
|
||||||
|
|
@ -326,7 +327,8 @@ class Items extends Model
|
||||||
|
|
||||||
public function getDisplayPriceAttribute()
|
public function getDisplayPriceAttribute()
|
||||||
{
|
{
|
||||||
try {
|
return $this->discount_price * $this->conversion;
|
||||||
|
/* try {
|
||||||
$convertion = $this->conversion_value();
|
$convertion = $this->conversion_value();
|
||||||
|
|
||||||
$price = @$this->variants->first()->reference->price->price ?? null;
|
$price = @$this->variants->first()->reference->price->price ?? null;
|
||||||
|
|
@ -336,7 +338,7 @@ class Items extends Model
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
*/ }
|
||||||
|
|
||||||
public function getDisplayPriceCurrencyAttribute()
|
public function getDisplayPriceCurrencyAttribute()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class BrandRepository
|
||||||
return Cache::remember('catalog_brand_'.json_encode($params), 60, function () use ($params) {
|
return Cache::remember('catalog_brand_'.json_encode($params), 60, function () use ($params) {
|
||||||
|
|
||||||
$category_id = @$params['category_id'];
|
$category_id = @$params['category_id'];
|
||||||
|
$limit = @$params['limit'];
|
||||||
if ($category_id) {
|
if ($category_id) {
|
||||||
$ids = DB::select('select distinct brand from store_category_map a
|
$ids = DB::select('select distinct brand from store_category_map a
|
||||||
left join item_dimension b
|
left join item_dimension b
|
||||||
|
|
@ -28,12 +29,15 @@ class BrandRepository
|
||||||
return Brand::whereIn('name', $ids)->orderBy('priority', 'desc')
|
return Brand::whereIn('name', $ids)->orderBy('priority', 'desc')
|
||||||
->where('priority', '>', 0)
|
->where('priority', '>', 0)
|
||||||
->orderBy('name', 'asc')
|
->orderBy('name', 'asc')
|
||||||
|
->take(10)
|
||||||
|
->withCount('items')
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Brand::orderBy('priority', 'desc')->orderBy('name', 'asc')
|
return Brand::orderBy('priority', 'desc')->orderBy('name', 'asc')
|
||||||
->where('priority', '>', 0)
|
->where('priority', '>', 0)
|
||||||
|
->take(10)
|
||||||
|
->withCount('items')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,16 @@ use DB;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Image;
|
use Image;
|
||||||
use Storage;
|
use Storage;
|
||||||
|
use Cache;
|
||||||
|
|
||||||
class CategoryRepository
|
class CategoryRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getList($params){
|
public function getList($params){
|
||||||
return Category::get();
|
return Cache::remember('catalog_category_'.json_encode($params), 60, function () use ($params) {
|
||||||
|
$limit = $params["limit"] ?? 7;
|
||||||
|
return Category::take($limit)->withCount('items')->get();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,14 @@ use DB;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Image;
|
use Image;
|
||||||
use Storage;
|
use Storage;
|
||||||
|
use Cache;
|
||||||
|
|
||||||
class GenderRepository
|
class GenderRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getList($params){
|
public function getList($params){
|
||||||
|
return Cache::remember('catalog_gender_'.json_encode($params), 60, function () use ($params) {
|
||||||
|
|
||||||
$category_id = @$params["category_id"];
|
$category_id = @$params["category_id"];
|
||||||
$brand_id = @$params["brand_id"];
|
$brand_id = @$params["brand_id"];
|
||||||
if ($category_id && $brand_id){
|
if ($category_id && $brand_id){
|
||||||
|
|
@ -28,9 +31,10 @@ class GenderRepository
|
||||||
where store_category_id = ? and brand = ?
|
where store_category_id = ? and brand = ?
|
||||||
and items.is_publish = true ",[$category_id, $brand->name]);
|
and items.is_publish = true ",[$category_id, $brand->name]);
|
||||||
$ids = collect($ids)->pluck("gender");
|
$ids = collect($ids)->pluck("gender");
|
||||||
return Gender::whereIn("name",$ids)->get();
|
return Gender::whereIn("name",$ids)->withCount('items')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Gender::get();
|
return Gender::withCount('items')->get();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,19 @@ class ProductRepository
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$builder = Items::select('items.*', 'percent')
|
$builder = Items::with([
|
||||||
|
'images',
|
||||||
|
'variants',
|
||||||
|
'reference'
|
||||||
|
])->select('items.*', 'percent')
|
||||||
|
->addSelect(DB::raw("coalesce(d.price, coalesce(pricelist.price, net_price)) as discount_price"))
|
||||||
|
->addSelect(DB::raw("to_qty / from_qty as conversion"))
|
||||||
|
->leftJoin("item_convertions", function($join){
|
||||||
|
$join->on("from_unit","=","items.unit");
|
||||||
|
$join->on("to_unit","=","items.display_unit");
|
||||||
|
})
|
||||||
->leftJoin('item_dimension', 'item_dimension.no', 'items.number')
|
->leftJoin('item_dimension', 'item_dimension.no', 'items.number')
|
||||||
->leftJoin(DB::raw("(select distinct on (item_id) item_id, percent, discounts.created_at,
|
->leftJoin(DB::raw("(select distinct on (item_id) item_id, percent, price, discounts.created_at,
|
||||||
case when discounts.valid_at is null then 'special-offer' else 'limited-sale' end as event
|
case when discounts.valid_at is null then 'special-offer' else 'limited-sale' end as event
|
||||||
from discount_items
|
from discount_items
|
||||||
left join item_reference on item_reference_id = item_reference.id
|
left join item_reference on item_reference_id = item_reference.id
|
||||||
|
|
@ -74,6 +84,17 @@ class ProductRepository
|
||||||
( discounts.valid_at is null or discounts.expired_at >= now())
|
( discounts.valid_at is null or discounts.expired_at >= now())
|
||||||
order by item_id, discounts.created_at desc
|
order by item_id, discounts.created_at desc
|
||||||
) as d"), 'd.item_id', '=', 'items.id')
|
) as d"), 'd.item_id', '=', 'items.id')
|
||||||
|
|
||||||
|
->leftJoin(DB::raw("(select distinct on (item_id) item_id, price
|
||||||
|
from discount_items
|
||||||
|
left join item_reference on item_reference_id = item_reference.id
|
||||||
|
left join discounts on discounts.id = discount_id
|
||||||
|
where discounts.type = 'price' and location_id is null and
|
||||||
|
( discounts.valid_at is null or discounts.valid_at <= now()) and
|
||||||
|
( discounts.valid_at is null or discounts.expired_at >= now())
|
||||||
|
order by item_id, discounts.created_at desc
|
||||||
|
) as pricelist"), 'pricelist.item_id', '=', 'items.id')
|
||||||
|
|
||||||
->when(true, function ($query) use ($event, $sort, $sorting_ids) {
|
->when(true, function ($query) use ($event, $sort, $sorting_ids) {
|
||||||
if ($event) {
|
if ($event) {
|
||||||
$query->orderByRaw("case when brand = 'CHAMELO' then 1 else 2 end ASC ");
|
$query->orderByRaw("case when brand = 'CHAMELO' then 1 else 2 end ASC ");
|
||||||
|
|
@ -96,7 +117,8 @@ class ProductRepository
|
||||||
} elseif ($sort == 'new') {
|
} elseif ($sort == 'new') {
|
||||||
$query->orderByRaw("case when category1 in ('CLUBS','CLUB','COMPONENT HEAD') and brand = 'PXG' then 1 else 2 end ASC");
|
$query->orderByRaw("case when category1 in ('CLUBS','CLUB','COMPONENT HEAD') and brand = 'PXG' then 1 else 2 end ASC");
|
||||||
} else {
|
} else {
|
||||||
$query->orderByRaw('case when d.created_at is not null then 1 else 2 end ASC, random()');
|
$query->orderByRaw('case when d.created_at is not null then 1 else 2 end ASC');
|
||||||
|
$query->inRandomOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +300,11 @@ class ProductRepository
|
||||||
|
|
||||||
public function show($slug)
|
public function show($slug)
|
||||||
{
|
{
|
||||||
$product = Items::where('slug', $slug)
|
$product = Items::with([
|
||||||
|
'images',
|
||||||
|
'variants',
|
||||||
|
'reference'
|
||||||
|
])->where('slug', $slug)
|
||||||
->when(is_int($slug), function ($query) use ($slug) {
|
->when(is_int($slug), function ($query) use ($slug) {
|
||||||
return $query->orWhere('id', $slug);
|
return $query->orWhere('id', $slug);
|
||||||
})
|
})
|
||||||
|
|
@ -305,6 +331,10 @@ class ProductRepository
|
||||||
// Remove except_ids from the list
|
// Remove except_ids from the list
|
||||||
$ids = array_diff($ids, (array) $except_ids);
|
$ids = array_diff($ids, (array) $except_ids);
|
||||||
|
|
||||||
return Items::whereIn('id', $ids)->inRandomOrder()->take(10)->get();
|
return Items::with([
|
||||||
|
'images',
|
||||||
|
'variants',
|
||||||
|
'reference'
|
||||||
|
])->whereIn('id', $ids)->inRandomOrder()->take(10)->get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class FooterBrands extends Component
|
||||||
*/
|
*/
|
||||||
public function __construct(BrandRepository $brandRepository)
|
public function __construct(BrandRepository $brandRepository)
|
||||||
{
|
{
|
||||||
$this->brands = $brandRepository->getList([]);
|
$this->brands = $brandRepository->getList(["limit"=>10]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class FooterCategory extends Component
|
||||||
*/
|
*/
|
||||||
public function __construct(CategoryRepository $categoryRepository)
|
public function __construct(CategoryRepository $categoryRepository)
|
||||||
{
|
{
|
||||||
$this->categories = $categoryRepository->getList([]);
|
$this->categories = $categoryRepository->getList(['limit' => 7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class FeaturedCategories extends Component
|
||||||
*/
|
*/
|
||||||
public function __construct(GenderRepository $genderRepository)
|
public function __construct(GenderRepository $genderRepository)
|
||||||
{
|
{
|
||||||
$this->genders = $genderRepository->getList([]);
|
$this->genders = $genderRepository->getList(['limit' => 7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ class HeaderCategoryDropdown extends Component
|
||||||
*/
|
*/
|
||||||
public function __construct(CategoryRepository $categoryRepository, GenderRepository $genderRepository)
|
public function __construct(CategoryRepository $categoryRepository, GenderRepository $genderRepository)
|
||||||
{
|
{
|
||||||
$this->categories = $categoryRepository->getList([]);
|
$this->categories = $categoryRepository->getList(['limit'=>7]);
|
||||||
$this->genders = $genderRepository->getList([]);
|
$this->genders = $genderRepository->getList(['limit'=>7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class PopularProducts extends Component
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|
||||||
$this->categories = $categoryRepository->getList([]);
|
$this->categories = $categoryRepository->getList(['limit'=>7]);
|
||||||
$this->products = $productRepository->getList([
|
$this->products = $productRepository->getList([
|
||||||
'limit' => 12,
|
'limit' => 12,
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,7 @@ class TopHeader extends Component
|
||||||
*/
|
*/
|
||||||
public function render(): View|Closure|string
|
public function render(): View|Closure|string
|
||||||
{
|
{
|
||||||
$brands = app(\App\Repositories\Catalog\BrandRepository::class)->getList([]);
|
$brands = app(\App\Repositories\Catalog\BrandRepository::class)->getList(["limit"=>10]);
|
||||||
|
|
||||||
return view('components.grocery.top-header', compact('brands'));
|
return view('components.grocery.top-header', compact('brands'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,12 @@ class NavbarCategory extends Component
|
||||||
$brandsRepository = new BrandRepository();
|
$brandsRepository = new BrandRepository();
|
||||||
|
|
||||||
|
|
||||||
$this->genders = $genderRepository->getList([]);
|
$this->genders = $genderRepository->getList(['limit' => 7]);
|
||||||
$this->genders = collect($this->genders)->chunk(7);
|
|
||||||
|
|
||||||
$this->categories = $categoryRepository->getList([]);
|
$this->categories = $categoryRepository->getList(['limit' => 7]);
|
||||||
// chunk
|
// chunk
|
||||||
$this->categories = collect($this->categories)->chunk(7);
|
|
||||||
|
|
||||||
$this->brands = $brandsRepository->getList([]);
|
$this->brands = $brandsRepository->getList(['limit' => 10]);
|
||||||
$this->brands = collect($this->brands)->chunk(7);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class Categories extends Component
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$categoryRepository = new CategoryRepository();
|
$categoryRepository = new CategoryRepository();
|
||||||
$this->categories = $categoryRepository->getList([]);
|
$this->categories = $categoryRepository->getList(['limit'=>7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
<div
|
<div
|
||||||
class="position-relative d-flex justify-content-between align-items-center h-100 bg-black rounded-5 overflow-hidden ps-2 ps-xl-3">
|
class="position-relative d-flex justify-content-between align-items-center h-100 bg-black rounded-5 overflow-hidden ps-2 ps-xl-3">
|
||||||
<div class="d-flex flex-column pt-4 px-3 pb-3">
|
<div class="d-flex flex-column pt-4 px-3 pb-3">
|
||||||
<p class="fs-xs pb-2 mb-1">{{ $value->productCount() }} products</p>
|
<p class="fs-xs pb-2 mb-1">{{ $value->items_count }} products</p>
|
||||||
<h2 class="h5 mb-2 mb-xxl-3">{{ $value->name }}</h2>
|
<h2 class="h5 mb-2 mb-xxl-3">{{ $value->name }}</h2>
|
||||||
<div class="nav">
|
<div class="nav">
|
||||||
<a class="nav-link animate-underline stretched-link text-body-emphasis text-nowrap px-0"
|
<a class="nav-link animate-underline stretched-link text-body-emphasis text-nowrap px-0"
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
<ul class="nav flex-column gap-2 mt-n2">
|
<ul class="nav flex-column gap-2 mt-n2">
|
||||||
|
|
||||||
@foreach ($categories as $category)
|
@foreach ($categories as $category)
|
||||||
@if ($category->productCount() > 0)
|
@if ($category->items_count > 0)
|
||||||
<li class="d-flex w-100 pt-1">
|
<li class="d-flex w-100 pt-1">
|
||||||
<a class="nav-link animate-underline animate-target d-inline fw-normal text-truncate p-0"
|
<a class="nav-link animate-underline animate-target d-inline fw-normal text-truncate p-0"
|
||||||
href="{{ route('product.index', ['category_id', $category->id]) }}">{{ $category->name }}</a>
|
href="{{ route('product.index', ['category_id', $category->id]) }}">{{ $category->name }}</a>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<div class="row nav g-3 g-sm-4">
|
<div class="row nav g-3 g-sm-4">
|
||||||
|
|
||||||
@foreach ($categories as $key => $value)
|
@foreach ($categories as $key => $value)
|
||||||
@if ($value->productCount() > 0)
|
@if ($value->items_count > 0)
|
||||||
<div class="col-sm-6 col-md-4 col-lg-12 d-flex">
|
<div class="col-sm-6 col-md-4 col-lg-12 d-flex">
|
||||||
<div class="position-relative d-flex min-w-0 align-items-center">
|
<div class="position-relative d-flex min-w-0 align-items-center">
|
||||||
<div class="d-flex flex-shrink-0 align-items-center justify-content-center bg-body-tertiary rounded-circle"
|
<div class="d-flex flex-shrink-0 align-items-center justify-content-center bg-body-tertiary rounded-circle"
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
href="{{ route('product.index', ['filter[category]' => $value->id]) }}">
|
href="{{ route('product.index', ['filter[category]' => $value->id]) }}">
|
||||||
<span class="animate-target text-truncate">{{ $value->name ?? '' }}</span>
|
<span class="animate-target text-truncate">{{ $value->name ?? '' }}</span>
|
||||||
</a>
|
</a>
|
||||||
<div class="fs-xs fw-normal text-body-secondary">{{ $value->productCount() }}
|
<div class="fs-xs fw-normal text-body-secondary">{{ $value->items_count }}
|
||||||
products
|
products
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue