Jump to content

How to set the default sorting of product list?


Lorraine1996

Recommended Posts

I often receive feedback from customers that the product listing page viewing experience is poor. If they buy a lot of individual products and some of them have expired. They will have a hard time clicking on the desired product quickly because of the mix of what works and what doesn't.

Although users can customize the sorting by clicking on the table column, some users don't know they can do so.

So, is it possible to set the default order of the product list? For example, this sorting would be better below.

Product status order: Active -> Pending -> Fraud -> Cancelled

Same product status: Sort by time of purchase from new to old

Any help, thanks in advance!

Link to comment
Share on other sites

a quick way to sort by status, would be to pass &orderby=domainstatus in the URL (possibly requiring a hook to modify the navbar link?) - but it's an alphabetical sort, so it would be Active -> Cancelled -> Fraud -> Pending -> Terminated etc

with regards to date of purchase, the products page wouldn't have access to it by default.

Link to comment
Share on other sites

8 hours ago, brian! said:

a quick way to sort by status, would be to pass &orderby=domainstatus in the URL (possibly requiring a hook to modify the navbar link?) - but it's an alphabetical sort, so it would be Active -> Cancelled -> Fraud -> Pending -> Terminated etc

with regards to date of purchase, the products page wouldn't have access to it by default.

I checked the WHMCS documentation and it shows how to delete/add the navigation bar link, no example of modifying the link. Can you provide an example? Thanks!

Currently I have created a hook file /includes/hooks/navbar.php

Link to comment
Share on other sites

7 hours ago, Lorraine1996 said:

I checked the WHMCS documentation and it shows how to delete/add the navigation bar link, no example of modifying the link. Can you provide an example? Thanks!

the quick way would be...

<?php 

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar){
	if (!is_null($primaryNavbar->getChild('Services')->getChild('My Services'))) {
		$primaryNavbar->getChild('Services')->getChild('My Services')->setURI('clientarea.php?action=services&orderby=domainstatus');
	}
});

I think an issue with this idea is that you would also need to change the link on the services panel on the client area homepage... that's a template edit or a jQuery hook.

21 hours ago, Lorraine1996 said:

So, is it possible to set the default order of the product list? For example, this sorting would be better below.

you could avoid making these link changes if you defined a default ordering preference in the clientareaproducts.tpl template...

{include file="$template/includes/tablelist.tpl" tableName="ServicesList" filterColumn="4" startOrderCol="[4, 'asc'], [1, 'asc']"}

that would sort alphabetically first on status and then on product name.

if you really wanted to do your (Active -> Pending -> Fraud -> Cancelled / Registration Date) sorting, I would probably suggest disabling ordering in the template (noOrdering="1"), and then sorting the $services array in a hook before returning the sorted array back to the template.

Link to comment
Share on other sites

21 hours ago, brian! said:

you could avoid making these link changes if you defined a default ordering preference in the clientareaproducts.tpl template...


{include file="$template/includes/tablelist.tpl" tableName="ServicesList" filterColumn="4" startOrderCol="[4, 'asc'], [1, 'asc']"}

that would sort alphabetically first on status and then on product name.

if you really wanted to do your (Active -> Pending -> Fraud -> Cancelled / Registration Date) sorting, I would probably suggest disabling ordering in the template (noOrdering="1"), and then sorting the $services array in a hook before returning the sorted array back to the template.

Implementing it is difficult for me, can you add specific steps?

After completing the first step, an issue arose where the product listing page could not be accessed. It was not until it was turned back to its original state that it returned to normal...

Link to comment
Share on other sites

On 05/06/2020 at 08:37, Lorraine1996 said:

After completing the first step, an issue arose where the product listing page could not be accessed. It was not until it was turned back to its original state that it returned to normal...

looks like I might have gave you a bum steer on this - trying the following:

remove the startOrderCol part, so that you're just left with the original line from the clientareaproducts.tpl template...

{include file="$template/includes/tablelist.tpl" tableName="ServicesList" filterColumn="4" noSortColumns="0"}

and then I would change...

        var table = jQuery('#tableServicesList').removeClass('hidden').DataTable();
        {if $orderby == 'product'}
            table.order([1, '{$sort}'], [4, 'asc']);
        {elseif $orderby == 'amount' || $orderby == 'billingcycle'}
            table.order(2, '{$sort}');
        {elseif $orderby == 'nextduedate'}
            table.order(3, '{$sort}');
        {elseif $orderby == 'domainstatus'}
            table.order(4, '{$sort}');
        {/if}
        table.draw();
        jQuery('#tableLoading').addClass('hidden');

to...

        var table = jQuery('#tableServicesList').removeClass('hidden').DataTable();
        table.order([4,'asc'],[1,'asc']);
        table.draw();
        jQuery('#tableLoading').addClass('hidden');

and unless i'm missing something, that should change the default order in status and then name.... it is working when testing locally and it's showing no errors.

Link to comment
Share on other sites

13 hours ago, brian! said:

remove the startOrderCol part, so that you're just left with the original line from the clientareaproducts.tpl template...


{include file="$template/includes/tablelist.tpl" tableName="ServicesList" filterColumn="4" noSortColumns=

Thanks, it worked!

noSortColumns="0" What is this parameter for? I have found no side effects with or without its use.

Link to comment
Share on other sites

6 hours ago, Lorraine1996 said:

noSortColumns="0" What is this parameter for? I have found no side effects with or without its use.

it specifies which column(s) can be sorted by clicking on their column headings... on the services page,  column #0 would be the SSL icon column - so leaving it in prevents users sorting on the icon values, removing it from the template means that they can.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated