From 3480c3da41ae440bcb92d5395c7488c1749313da Mon Sep 17 00:00:00 2001 From: Serhii Korneliuk Date: Fri, 19 Jan 2024 14:46:53 +0200 Subject: [PATCH] [ADD] Products sort. --- module/sCommerceModule.php | 17 ++++++++++++++++- views/index.blade.php | 11 +++++++++++ views/partials/pagination.blade.php | 13 ++++--------- views/partials/style.blade.php | 2 +- views/productsTab.blade.php | 5 ----- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/module/sCommerceModule.php b/module/sCommerceModule.php index b8aed14..073cb16 100644 --- a/module/sCommerceModule.php +++ b/module/sCommerceModule.php @@ -5,6 +5,7 @@ use Illuminate\Pagination\Paginator; use Illuminate\Support\Facades\Cookie; +use Illuminate\Support\Facades\DB; use Seiger\sCommerce\Controllers\sCommerceController; use Seiger\sCommerce\Facades\sCommerce; use Seiger\sCommerce\Models\sProduct; @@ -45,8 +46,22 @@ $perpage = Cookie::get('scom_products_page_items', 50); $order = request()->input('order', 'id'); $direc = request()->input('direc', 'desc'); + $query = sProduct::lang($sCommerceController->langDefault())->search(); + + switch ($order) { + case "category": + $query->addSelect( + '*', + DB::Raw('(select `' . DB::getTablePrefix() . 'site_content`.`pagetitle` from `' . DB::getTablePrefix() . 'site_content` where `' . DB::getTablePrefix() . 'site_content`.`id` = `' . DB::getTablePrefix() . 's_products`.`category`) as cat') + ); + $query->orderBy('cat', $direc); + break; + default : + $query->orderBy($order, $direc); + break; + } - $data['items'] = sProduct::lang($sCommerceController->langDefault())->search()->orderBy($order, $direc)->paginate($perpage); + $data['items'] = $query->paginate($perpage); $data['total'] = sProduct::count(); $data['active'] = sProduct::wherePublished(1)->count(); $data['disactive'] = $data['total'] - $data['active']; diff --git a/views/index.blade.php b/views/index.blade.php index 6690b0b..80e4aa1 100644 --- a/views/index.blade.php +++ b/views/index.blade.php @@ -116,6 +116,17 @@ function() { return false; }); + // Ordering + $('.sorting').on('click', function () { + const urlParams = new URLSearchParams(window.location.search); + const order = $(this).attr('data-order'); + let direc = 'asc'; + if (urlParams.get('order') == order && urlParams.get('direc') == direc) { + direc = 'desc'; + } + window.location.href = '{!!$moduleUrl!!}&get=products&order='+order+'&direc='+direc; + }); + // Flash messages @if (session()->has('success')) alertify.success("{{session('success')}}"); diff --git a/views/partials/pagination.blade.php b/views/partials/pagination.blade.php index 448a025..4e72160 100644 --- a/views/partials/pagination.blade.php +++ b/views/partials/pagination.blade.php @@ -1,15 +1,10 @@ @if ($paginator->hasPages()) {{-- Full link generate --}} @php - switch (request()->get('get')) - { - //case 'comments': - // $fullUrl = sCommerce::moduleUrl() . '&get='.request()->get('get'); - // break; - default: - $fullUrl = sCommerce::moduleUrl() . (request()->has('search') ? '&search=' . request()->search : ''); - break; - } + $fullUrl = sCommerce::moduleUrl() . '&get='.request()->get('get'); + $fullUrl .= (request()->has('search') ? '&search=' . request()->search : ''); + $fullUrl .= (request()->has('order') ? '&order=' . request()->order : ''); + $fullUrl .= (request()->has('direc') ? '&direc=' . request()->direc : ''); $paginator->withPath($fullUrl); @endphp diff --git a/views/partials/style.blade.php b/views/partials/style.blade.php index 35670a9..4f18557 100644 --- a/views/partials/style.blade.php +++ b/views/partials/style.blade.php @@ -6,7 +6,6 @@ #copyright{position:fixed;bottom:0;right:0;} #copyright img{width:35px;} #img-preview{border:1px solid #ccc;position:fixed;top:50%;left:50%;width:600px;margin-top:-300px;margin-left:-300px;display:none;} - #main-logo{color:#0B78FF;} #preview.form-control{max-width:85px;background:#CECECF;} input[type=checkbox], input[type=radio] {padding:0.5em;} table .product-thumbnail{width:70px;height:45px;} @@ -65,6 +64,7 @@ .seiger__list{display:flex;align-items:center;justify-content:flex-end;} .seiger__label{display:inline-block;color:#63666b;font-family:inherit;font-size:14px;font-weight:400;line-height:130%;margin-right:10px;white-space:nowrap;} .seiger__module-table{width:calc(100% + 60px);margin-left:-40px;} + .sorted{font-style:italic;} .dropdown{position:relative;} .dropdown .dropdown__title{padding:8px 12px;display:flex;align-items:center;border-radius:6px;border:1px solid #cececf;background:#fff;cursor:pointer;outline:none;} .dropdown .dropdown__title span{display:inline-block;margin-right:4px;font-family:inherit;font-size:14px;font-weight:400;line-height:120%;} diff --git a/views/productsTab.blade.php b/views/productsTab.blade.php index 739a0d4..ead21f4 100644 --- a/views/productsTab.blade.php +++ b/views/productsTab.blade.php @@ -208,11 +208,6 @@ class="form-control rounded-left scom-input seiger__search"