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

Ventsi Genchev

  • Jr. Member
  • **
  • Posts: 202
    • 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 / 3.2.14.9808

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:
/administrator/components/com_virtuemart/models/product.php
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 - https://joomla.bypv.org/en/.
No pain, no gain, no site!

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9591
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Fix in categories - Sort by
« Reply #1 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?
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Ventsi Genchev

  • Jr. Member
  • **
  • Posts: 202
    • Bulgarian Computer Store
Re: Fix in categories - Sort by
« Reply #2 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 +/-
Example:
https://demo.virtuemart.net/product-attributes/by,product_name?keyword=
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.
No pain, no gain, no site!

aftertaf

  • Jr. Member
  • **
  • Posts: 200
    • sO couture
  • VirtueMart Version: 3.2.14
Re: Fix in categories - Sort by
« Reply #3 on: May 20, 2018, 18:34:36 pm »
Hi,
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: http://www.socouture.fr/tissus (500+ products)
this one seems to work fine though : http://www.socouture.fr/patrons (84 products)
Any clue what could be wrong ?
david


edit:
brainfart...... -> i was displaying featured products
Webmaster for my wife (link in my profile ;)
Extensions / plugins : POSForWebshops, TemplatecreatorCK ,MaximenuCK, and PageBuilderCK, VM BatchEdit Pro, VM CustomFilters Pro, Awocoupon Pro, slogin, supersaas,  among other things...
Joomla! 3.8.6//VM 3.2.14//PHP7.0.18 & mariadb 10.1.22 on Debian
big up to notepad++!!!!