Author Topic: Fix in categories - Sort by  (Read 57 times)

Venci Gentchev

  • Jr. Member
  • **
  • Posts: 191
    • Bulgarian Computer Store
Fix in categories - Sort by
« 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:
  • If you want the products in the categories to be sorted by the last added product, choose in the administration:
    Default product sort order: Creation Date, Descending
    What users will see by default, setting by creation date will always be DESC (+/-) and for all others as product name, price, and others - ASC (-/+). Unless the user chooses otherwise.
    Of course, in the administration you can choose any other way of arranging.

  • Corrected character display -/+ (= Ascending) and +/- (= Descending).

  • Remember the sort selected by the user when switching to another category (for the session). Including the arrangement (ascending or descending). Like the number of products per page are remembered if the user changes them.

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'

$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 -
No pain, no gain, no site!