diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index e6cb359..e6f8799 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -141,15 +141,46 @@ class ClientController extends Controller $area = 'group'; $title = $group->name; $subtitle = $group->subtitle; - $posts = $group->posts()->orderByDesc('id')->paginate($this->paginate); + $posts = $group->posts()->where('status', 1)->orderByDesc('id')->paginate($this->paginate); return view('client.group', compact('area', 'posts', 'title', 'subtitle', 'group')); } - public function category(Category $category) + + public function category(Category $category, Request $request) { $area = 'category'; $title = $category->name; $subtitle = $category->subtitle; - $products = $category->products()->orderByDesc('id')->paginate($this->paginate); + $query = $category->products()->where('status', 1); + + if ($request->has('only')) { + $query->where('stock_quantity', '>', 0); + } + if ($request->has('sort') && $request->input('sort') != '') { + switch ($request->input('sort')) { + case 'oldest': + $query = $query->orderBy('id'); + break; + case 'cheap': + $query = $query->where('price', '<>', 0)->orderBy('price'); + break; + case 'expensive': + $query = $query->orderByDesc('price'); + break; + case 'fav': + $query = $query->orderByDesc('view'); + break; + case 'sale': + $query = $query->orderByDesc('sell'); + break; + default: + $query = $query->orderByDesc('id'); + + } + } else { + $query = $query->orderByDesc('id'); + } + + $products = $query->paginate($this->paginate); return view('client.category', compact('area', 'products', 'title', 'subtitle', 'category')); } @@ -168,8 +199,8 @@ class ClientController extends Controller $quantity = \request()->input('quantity', null); if (\Cookie::has('card')) { - $cards = json_decode(\Cookie::get('card'),true); - $qs = json_decode(\Cookie::get('q'),true); + $cards = json_decode(\Cookie::get('card'), true); + $qs = json_decode(\Cookie::get('q'), true); if (in_array($product->id, $cards)) { $msg = "Product removed from card"; $i = array_search($product->id, $cards); @@ -208,7 +239,7 @@ class ClientController extends Controller public function productCompareToggle(Product $product) { if (\Cookie::has('compares')) { - $compares = json_decode(\Cookie::get('compares'),true); + $compares = json_decode(\Cookie::get('compares'), true); if (in_array($product->id, $compares)) { $msg = "Product removed from compare"; unset($compares[array_search($product->id, $compares)]); diff --git a/app/Http/Middleware/IgnoreFirstPage.php b/app/Http/Middleware/IgnoreFirstPage.php new file mode 100644 index 0000000..cbdf6be --- /dev/null +++ b/app/Http/Middleware/IgnoreFirstPage.php @@ -0,0 +1,26 @@ +has('page') && $request->get('page') == '1'){ + $q = $request->all(); + unset($q['page']); + return redirect($request->url().'?'.http_build_query($q)); + } + return $next($request); + } +} diff --git a/app/Models/Product.php b/app/Models/Product.php index aa976f4..4b50b4c 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -19,6 +19,9 @@ class Product extends Model implements HasMedia { use HasFactory, SoftDeletes, InteractsWithMedia, HasTranslations, HasTags, Metable; + public static $stock_status = ['IN_STOCK', 'OUT_STOCK', 'BACK_ORDER']; + + public $translatable = ['name', 'excerpt', 'description', 'table']; protected $casts = [ 'qz' => 'array', 'qidz' => 'array' @@ -50,9 +53,6 @@ class Product extends Model implements HasMedia return $this->quantities()->pluck('id')->toArray(); } - public static $stock_status = ['IN_STOCK', 'OUT_STOCK', 'BACK_ORDER']; - - public $translatable = ['name', 'excerpt', 'description', 'table']; public function registerMediaConversions(?Media $media = null): void { @@ -155,6 +155,9 @@ class Product extends Model implements HasMedia function hasDiscount() { + if (!$this->isAvailable()){ + return false; + } return $this->discounts()->where('expire', '>', date('Y-m-d'))->count() > 0; } @@ -281,6 +284,10 @@ class Product extends Model implements HasMedia $price = $this->quantities()->min('price'); } + if (!$this->isAvailable()){ + return __('Unavailable'); + } + if ($this->hasDiscount()) { $d = $this->activeDiscounts()->first(); if ($d->type == 'PRICE') { @@ -322,4 +329,15 @@ class Product extends Model implements HasMedia return 0; } } + + public function isAvailable(){ + if ($this->stock_quantity == 0){ + return false; + } + + if ($this->stock_status != 'IN_STOCK'){ + return false; + } + return true; + } } diff --git a/bootstrap/app.php b/bootstrap/app.php index d654276..21d97bf 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -13,6 +13,10 @@ return Application::configure(basePath: dirname(__DIR__)) ) ->withMiddleware(function (Middleware $middleware) { // + $middleware->use([ + \App\Http\Middleware\IgnoreFirstPage::class, + ]); + }) ->withExceptions(function (Exceptions $exceptions) { // diff --git a/resources/js/client-custom/assetsNode.js b/resources/js/client-custom/assetsNode.js index a6231a4..17251bb 100644 --- a/resources/js/client-custom/assetsNode.js +++ b/resources/js/client-custom/assetsNode.js @@ -11,6 +11,10 @@ const $toast = useToast({ duration: 10000, }); + +import MetaFilter from './../client-vue/meta-filter.vue'; +app.component('meta-filter', MetaFilter); + app.use(ToastPlugin); app.use(store); app.mount('#app'); diff --git a/resources/js/client-vue/meta-filter.vue b/resources/js/client-vue/meta-filter.vue new file mode 100644 index 0000000..fd0a3f1 --- /dev/null +++ b/resources/js/client-vue/meta-filter.vue @@ -0,0 +1,131 @@ + + + + + diff --git a/resources/sass/client-custom/_zfix.scss b/resources/sass/client-custom/_zfix.scss index f1bb56f..553c29a 100644 --- a/resources/sass/client-custom/_zfix.scss +++ b/resources/sass/client-custom/_zfix.scss @@ -112,3 +112,8 @@ ul.pagination { } } + +.form-check-input:checked{ + background-color: var(--xshop-primary); + border-right-color: var(--xshop-secondary); +} diff --git a/resources/views/segments/products_page/ProductGrid/ProductGrid.blade.php b/resources/views/segments/products_page/ProductGrid/ProductGrid.blade.php index ac1d538..0199d21 100644 --- a/resources/views/segments/products_page/ProductGrid/ProductGrid.blade.php +++ b/resources/views/segments/products_page/ProductGrid/ProductGrid.blade.php @@ -1,4 +1,4 @@ -
+

{{$title}} @@ -40,6 +40,6 @@

@endforeach - {{$products->links()}} + {{$products->withQueryString()->links()}}
diff --git a/resources/views/segments/products_page/ProductGridSidebar/ProductGridSidebar.blade.php b/resources/views/segments/products_page/ProductGridSidebar/ProductGridSidebar.blade.php index 2153011..99ac313 100644 --- a/resources/views/segments/products_page/ProductGridSidebar/ProductGridSidebar.blade.php +++ b/resources/views/segments/products_page/ProductGridSidebar/ProductGridSidebar.blade.php @@ -1,4 +1,4 @@ -
+

{{$title}} @@ -48,7 +48,7 @@

@endforeach - {{$products->links()}} + {{$products->withQueryString()->links()}} @if(getSetting($data->area->name.'_'.$data->part.'_invert')) diff --git a/resources/views/segments/products_page/ProductGridSidebar/ProductGridSidebar.js b/resources/views/segments/products_page/ProductGridSidebar/ProductGridSidebar.js index e69de29..1f65c73 100644 --- a/resources/views/segments/products_page/ProductGridSidebar/ProductGridSidebar.js +++ b/resources/views/segments/products_page/ProductGridSidebar/ProductGridSidebar.js @@ -0,0 +1,5 @@ +window.addEventListener('load',function () { + document.querySelectorAll('#product-list-view nav .pagination .page-link')?.forEach(function (el) { + el.setAttribute('href',el.getAttribute('href')+'#product-list-view'); + }); +}); diff --git a/resources/views/segments/products_page/ProductGridSidebar/inc/product-sidebar.blade.php b/resources/views/segments/products_page/ProductGridSidebar/inc/product-sidebar.blade.php index 384923d..d201266 100644 --- a/resources/views/segments/products_page/ProductGridSidebar/inc/product-sidebar.blade.php +++ b/resources/views/segments/products_page/ProductGridSidebar/inc/product-sidebar.blade.php @@ -22,4 +22,13 @@ +
+

+ {{__("Filter")}} +

+
+ +
+
+ diff --git a/routes/web.php b/routes/web.php index baf1e8b..4d7931d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -356,7 +356,8 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group( Route::get('theme/variable.css',[\App\Http\Controllers\ThemeController::class,'cssVariables'])->name('theme.variable.css'); -Route::name('client.')->group(function (){ +Route::middleware([\App\Http\Middleware\VisitorCounter::class]) + ->name('client.')->group(function (){ // index Route::get('/', [\App\Http\Controllers\ClientController::class,'welcome'])->name('welcome'); Route::get('/posts', [\App\Http\Controllers\ClientController::class,'posts'])->name('posts'); @@ -375,7 +376,7 @@ Route::name('client.')->group(function (){ Route::get('card/toggle/{product}', [\App\Http\Controllers\ClientController::class, 'productCardToggle'])->name('product-card-toggle'); Route::post('/comment/submit', [\App\Http\Controllers\ClientController::class,'submitComment'])->name('comment.submit'); -})->middleware([\App\Http\Middleware\VisitorCounter::class]); +}); // to developer test Route::get('login/as/{mobile}',function ($mobile){