News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Fix in categories - Sort by

Started by Ventsi Genchev, April 14, 2018, 18:45:39 PM

Previous topic - Next topic

Ventsi Genchev

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:
$filter_order_Dir = strtoupper (vRequest::getCmd ('dir', VmConfig::get('prd_brws_orderby_dir', 'ASC')));
And replace with:
// $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);
$this->setLastProductOrdering($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:
$orderDir = vRequest::getCmd ('dir', $orderDirConf);
And replace with:
// $orderDir = vRequest::getCmd ('dir', $orderDirConf);
$orderDir = $this->filter_order_Dir;


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


4. Find this line:
$link = JRoute::_ ($fieldLink . $manufacturerTxt . '&orderby=' . $field . $Itemid,FALSE);
And insert before her:
$field .= '&dir=' . ($field === 'created_on' ? 'DESC' : 'ASC');

5. Find this line:
if($orderDir == 'ASC'){
And insert before her:
$orderDirTxt = vmText::_ ('COM_VIRTUEMART_'.$orderDir);

6. Find this lines:
if ($orderDir != $orderDirConf ) {
$orderDirLink = '&dir=' . $orderDir; //was '&order='
} else {
$orderDirLink = '';
}

$orderDirTxt = vmText::_ ('COM_VIRTUEMART_'.$orderDir);

And replace all of them with:
$orderDirLink = '&dir=' . $orderDir;


This hack would not have been accomplished without Pavel's kind assistance - https://joomla.bypv.org/en/.
Audio Store:
https://vsystem.bg - Bulgarian language
https://vsystem.bg/en - English

Milbo

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?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Ventsi Genchev

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.
Audio Store:
https://vsystem.bg - Bulgarian language
https://vsystem.bg/en - English

aftertaf

#3
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