Sort By Product Code 4.x

I've been constantly having to add this in CSC since version 1.x and not sure why CSC has not added it all these years, however I have just discovered that pagination sorting (previous/next) doesn't follow my added product code sorting so there must be somewhere else I need to edit. I don't know if my brain is spent from the week but for the life of me I cannot find where it would be. Any help would be appreciated.

/app/functions/fn.catalog.php

function fn_get_products_sorting()
{
    $sorting = array(
        'null' => array('description' => __('none'), 'default_order' => 'asc', 'desc' => false),
        'timestamp' => array('description' => __('date'), 'default_order' => 'desc'),
        'position' => array('description' => __('default'), 'default_order' => 'asc'),
        'code' => array('description' => __('code'), 'default_order' => 'asc'), // sort by code The Tool
        'product' => array('description' => __('name'), 'default_order' => 'asc'),
        'price' => array('description' => __('price'), 'default_order' => 'asc'),
        'popularity' => array('description' => __('popularity'), 'default_order' => 'desc')
    );

Might want to change

'code' => array('description' => __('code'), 'default_order' => 'asc'), // sort by code The Tool

to

'product_code' => array('description' => __('code'), 'default_order' => 'asc'), // sort by code The Tool

There is no 'code' column in the products table.

Hey Tony,

My products do actually sort by product code in both admin and frontend in all the list views. It's just the pagination (previous/next product) when you are actually on the product page that doesn't.

But I will look into your solution.

Could be that they translate 'code' from the parameters to 'cscart_products.product_code'

If you're hooked into the 'pre-query' side of things, then it should be maintained through pagination. However, if you're doing it 'post-query' then you probably have to do it at a later point in the process. But then it might just sort by the data on the page rather than the data from the query (if you get what I'm trying to say).

The code in the first message is correct since the identifier for the sorting by code is defined in the fn_get_products function:

    $sortings = array (
        'code' => 'products.product_code',
        ....

As for the error, please do the following:

- enable error displaying and development mode in the config.local.php file

- make a right click on any page in the list of pages

- select the "Open in new tab" option

- check the result

Just to be clear, it's not the list pages where the issue is. On the product details page where you can select Previous/Next product is where the issue is. I'm not sure what sorting is being used but it does not go to the previous or next product code.

Just to be clear, it's not the list pages where the issue is. On the product details page where you can select Previous/Next product is where the issue is. I'm not sure what sorting is being used but it does not go to the previous or next product code.

Ah, ok. Just try the same thing with enabled error displaying

ecom,

Why do you think there is an error? I am assuming that additional code needs to be added for the Previous/Next sorting on the product details page but I cannot find where.

Sorry, I misunderstood your initial message. You should check the following file and find how the previous and next product IDs are calculated:

app/Tygh/Navigation/LastView/ACommon.php

More thoughts and observances on this issue.

It seems this is probably an issue for anyone that selects a different default sorting than the original default sorting (Newest).? I say this because on an initial page load (clean browser cache), if you select a list page, whether it be a category or a brand, and you select the first product in the list, unless it is the Newest product you will see that in the Previous/Next view that it is not in the number 1 position. However, if you go back to the list page and select other list views it works properly and even if you go back to the default list view, which mine is Grid, it works properly.

Probably a "Working as designed" bug.?