Skip to content

Commit

Permalink
[ADD] Products sort.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiger committed Jan 19, 2024
1 parent 19151ae commit 3480c3d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
17 changes: 16 additions & 1 deletion module/sCommerceModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
Expand Down
11 changes: 11 additions & 0 deletions views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')}}");
Expand Down
13 changes: 4 additions & 9 deletions views/partials/pagination.blade.php
Original file line number Diff line number Diff line change
@@ -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
<style>.dark #translatePagination a {color: #444}</style>
Expand Down
2 changes: 1 addition & 1 deletion views/partials/style.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
Expand Down Expand Up @@ -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%;}
Expand Down
5 changes: 0 additions & 5 deletions views/productsTab.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,6 @@ class="form-control rounded-left scom-input seiger__search"
</div>
</div>
<script>
$('.sorting').on('click', function () {
let order = $(this).attr('data-order');
let direc = $(this).attr('data-direc');
window.location.href = '{!!$moduleUrl!!}&get=products&order='+order+'&direc='+direc;
});
$('.js_delete').on('click', function () {
let subscriber = $(this).closest('tr').attr('id').split('-')[1];
alertify
Expand Down

0 comments on commit 3480c3d

Please sign in to comment.