VirtueMart Forum

VirtueMart 2 + 3 => Virtuemart Development and bug reports => Topic started by: Ventsi Genchev on April 14, 2018, 18:45:39 pm

Title: Fix in categories - Sort by
Post by: Ventsi Genchev on April 14, 2018, 18:45:39 pm
First of all I have to note that this is hardcoded hack. After an update of the VM, it will need to be re-applied.
Unless Max decides to use it, which I hope.  :)

Tested in VM versions: 3.2.12 /

What does this hack do:

Changes are only in the file:
Be sure to save the original file for each case before making the changes!

1. Find this line:
Code: [Select]
$filter_order_Dir = strtoupper (vRequest::getCmd ('dir', VmConfig::get('prd_brws_orderby_dir', 'ASC')));And replace with:
Code: [Select]
// $filter_order_Dir = strtoupper (vRequest::getCmd ('dir', VmConfig::get('prd_brws_orderby_dir', 'ASC')));

$filter_order = strtolower($app->getUserStateFromRequest(
  'com_virtuemart.category.filter_order', 'orderby', VmConfig::get ('browse_orderby_field'), 'string'

$fields_list = VmConfig::get ('browse_orderby_fields');
if(!in_array($filter_order, $fields_list)) {
$filter_order = $this->checkFilterOrder ($filter_order);
$filter_order_Dir = strtoupper($app->getUserStateFromRequest(
  'com_virtuemart.category.filter_order_Dir', 'dir', ($filter_order === '`p`.created_on' ? 'DESC' : 'ASC'), 'word'

2. Find this line:
Code: [Select]
$orderDir = vRequest::getCmd ('dir', $orderDirConf);And replace with:
Code: [Select]
// $orderDir = vRequest::getCmd ('dir', $orderDirConf);
$orderDir = $this->filter_order_Dir;

3. Find this line:
Code: [Select]
$orderby = vRequest::getString ('orderby', $orderbyCfg);And replace with:
Code: [Select]
// $orderby = vRequest::getString ('orderby', $orderbyCfg);
$orderby = $this->filter_order;

4. Find this line:
Code: [Select]
$link = JRoute::_ ($fieldLink . $manufacturerTxt . '&orderby=' . $field . $Itemid,FALSE);And insert before her:
Code: [Select]
$field .= '&dir=' . ($field === 'created_on' ? 'DESC' : 'ASC');
5. Find this line:
Code: [Select]
if($orderDir == 'ASC'){And insert before her:
Code: [Select]
$orderDirTxt = vmText::_ ('COM_VIRTUEMART_'.$orderDir);
6. Find this lines:
Code: [Select]
if ($orderDir != $orderDirConf ) {
$orderDirLink = '&dir=' . $orderDir; //was '&order='
} else {
$orderDirLink = '';

$orderDirTxt = vmText::_ ('COM_VIRTUEMART_'.$orderDir);
And replace all of them with:
Code: [Select]
$orderDirLink = '&dir=' . $orderDir;

This hack would not have been accomplished without Pavel's kind assistance -
Title: Re: Fix in categories - Sort by
Post by: Milbo on May 09, 2018, 09:59:40 am
I wonder, actually the whole thing should work just with the hidden config

VmConfig::get('prd_brws_orderby_dir', 'ASC')

so prd_brws_orderby_dir = DESC should have the same effect, and without any hack. Not?
Title: Re: Fix in categories - Sort by
Post by: Ventsi Genchev on May 09, 2018, 11:05:18 am
Max, thank you for your reply.

Unfortunately, the hidden config does not do what is described.
The idea is by default the sort by date of adding the product to always be a DESC (first to see the latest products). All other types of sorting should be an ASC. For example, sorting by name should be an ASC.

But not only that is what is important in this hack:
Fixed display of +/-
Shows product sorting +/-. This means DESC. From letter "z" to letter "a". But real sorting is ASC (-/+).

Remember the sort selected by the user when switching to another category (for the session). Including the arrangement (ascending or descending).
That means:
If the user chooses sorting different than the default when he goes to another category, the selected sort is the same as he chooses. It is not the default. This only applies to the session. Like the number of products per page are remembered if the user changes them.
Title: Re: Fix in categories - Sort by
Post by: aftertaf on May 20, 2018, 18:34:36 pm
maybe i'm hijacking the thread a little, but i want to display all products that are in a category or in a child category under this parent category. This works.
I would like to make them display by alphabetical order, but it doesn't seem to work.

J3.8.7 / VM 3.2.14.

Ive set the default sort option in Configuration to be Product Name.
The result isn't even sorted byt products within their child category, it just seems random : when i refresh, different products show, so its not using any internal (but unseen by me) ordering...

Page with problem: (500+ products)
this one seems to work fine though : (84 products)
Any clue what could be wrong ?

brainfart...... -> i was displaying featured products