News:

Looking for documentation? Take a look on our wiki

Main Menu

Order product by DESC

Started by saiborg, January 26, 2012, 13:24:34 PM

Previous topic - Next topic

saiborg

When i show virtuemart home page the product will show in ASC order , (the oldest first) how can i change this with the newest first ?
In the configuration i use date_created_on , if i press this option (in selectbox) is correct but i would that was by default
Thanks , Saiborg

TopPretender

change file: /administrator/components/com_virtuemart/models/product.php
Find the following code:
/* invert order value set*/
if ($order =='ASC') {
$orderlink ='&order=DESC';
$orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_DESC');
} else {
$orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_ASC');
$orderlink ='';
}


and just switch the order. Be AWARE that this will change all your default sort by to descend.

ALSO, Do you have SEF on or off?

if SEF on, then go to /components/com_virtuemart/router.php.
Inside the file, move the following:
if ( isset($query['order']) ) {
if ($query['order'] =='DESC') $segments[] = $helper->lang('orderDesc') ;
unset($query['order']);
}

to after
if ( isset($query['orderby']) ) {
$segments[] = $helper->lang('by').','.$helper->lang( $query['orderby']) ;
unset($query['orderby']);
}

slammy

hmm, that does not work for me. I am using J 2.5.4 and VM2.0.6. The code you mentioned in administrator/components/com_virtuemart/models/product.php:

        /* invert order value set*/
        if ($order =='ASC')  { //ASC
                $orderlink ='&order=DESC'; //DESC
                $orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_DESC');//DESC
        } else {
                $orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_ASC');//ASC
                $orderlink ='';
        }


is for generating the right user-switching-link for the ordering direction in the productoverview-pages. It has nothing to do to set up the default ordering direction/ filter_order_dir.
Can someone help? There are several threads here in this forum concerning the asc and desc issue in the product-overviews:

http://forum.virtuemart.net/index.php?topic=100499.0;topicseen
http://forum.virtuemart.net/index.php?topic=96569.msg336064#msg336064
http://forum.virtuemart.net/index.php?topic=100546.msg333871#msg333871


but it seems that there is no solution for it, does one of the hero members have an answer?
would be great, thx in advance
slam


gamecat2300

Hello,

We are in the same boat. It seems off that this isn't an option in the admin section. Regardless we are also a bit stumped as to where the sort DESC/ASC option resides. This post doesn't seem to resolve this issue for us either.

=-s-=

slammy

Hi,

I have a minimal solution, read last post from me of this thread:

http://forum.virtuemart.net/index.php?topic=103141.msg343650#msg343650

regards slam

FcVM


bytelord

Did you follow the above instructions and didn't work for you?
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

Peter Pillen

my fix

Go to file /administrator/components/com_virtuemart/models/product.php

search for the line that says (somewhere around line 143)
$filter_order_Dir = strtoupper (JRequest::getWord ('order', 'ASC'));

change that to
$filter_order_Dir = strtoupper (JRequest::getWord ('order', 'DESC'));

This doesn't order the products descending on their creation date, but their product id. It's about the same thing. Product id's are auto incrementing in the mysql database, so it is also a kind of "last created" feature to it.

Hope this helps ;)

FcVM

I did as recommended P2 Peter.
In this default sort was good. But it does not switch when press "- /+". It's bad.

TopPretender advised to change the code:
/* invert order value set*/
if ($order =='ASC') {
$orderlink ='&order=DESC';
$orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_DESC');
} else {
$orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_ASC');
$orderlink ='';
}

But he did not say how to change it.

Peter Pillen

#9
Okay... I missed that. Could you try this for me? I think I have the solution now. The problem was in the links.

Part 1: changing ASC to DESC

file : /administrator/components/com_virtuemart/models/product.php

approximatly @ line 95
var $filter_order_Dir = 'ASC';
change ASC to DESC

approximatly @ line 115
$this->filter_order_Dir = 'ASC';
change ASC to DESC

approximatly @ line 145
$filter_order_Dir = strtoupper (JRequest::getWord ('order', 'ASC'));
change ASC to DESC

approximatly @ line 1749
$order = JRequest::getWord ('order', 'ASC');
if ($order == 'DESC') {
$orderTxt .= '&order=' . $order;
}

change to
$order = JRequest::getWord ('order', 'DESC');
if ($order == 'ASC') {
$orderTxt .= '&order=' . $order;
}


approximatly @ line 1857
if ($order == 'ASC') {
$orderlink = '&order=DESC';
$orderTxt = JText::_ ('COM_VIRTUEMART_SEARCH_ORDER_DESC');
}
else {
$orderTxt = JText::_ ('COM_VIRTUEMART_SEARCH_ORDER_ASC');
$orderlink = '';
}

change second $orderlink value
if ($order == 'ASC') {
$orderlink = '&order=DESC';
$orderTxt = JText::_ ('COM_VIRTUEMART_SEARCH_ORDER_DESC');
}
else {
$orderTxt = JText::_ ('COM_VIRTUEMART_SEARCH_ORDER_ASC');
$orderlink = '&order=ASC';
}


Part 2: To make it work with Joomla SEF urls you need to edit the following

file : /components/com_virtuemart/router.php

approximatly @ line 92
if ($query['order'] =='DESC') $segments[] = $helper->lang('orderDesc') ;
change to
if ($query['order'] =='ASC') $segments[] = $helper->lang('orderAsc') ;

approximatly @ line 358
if (  $helper->compareKey(end($segments),'orderDesc') ){
//$vars['order'] ='DESC'

change to
if (  $helper->compareKey(end($segments),'orderAsc') ){
$vars['order'] ='ASC' ;


FcVM

P2 Peter
It works. Thank you so much  :)

Peter Pillen

Thanks! I'm glad it works too ;)

Only one problem... we'll probably will be doing this again after each virtuemart and/or joomla update  :-\

Peter Pillen

I have found an additional problem with my fix.

The navigation "next product" and "previous product" in the productdetails page isn't correct with this fix. It displays the products alfabetically in my case instead of the ASC DESC order in the category view.

I'll have a go at it later on, but if someone knows the answer already... please share

guidocx842

Quote from: P2 Peter on November 25, 2012, 16:10:37 PM
I have found an additional problem with my fix.

The navigation "next product" and "previous product" in the productdetails page isn't correct with this fix. It displays the products alfabetically in my case instead of the ASC DESC order in the category view.

I'll have a go at it later on, but if someone knows the answer already... please share

Hi! I've the same needs of saiborg and I find this post. I've tried your fix P2 Peter and I think I found another problem... the DESC property is applied to ALL the possible kind of order. So, I see my products orderered DESC like I needs if I set to order by creation date. Like a category blog. But if I give the users the capability to order items also by name, in that case, in my opinion, it is preferable to order ASC.
Do you discover any other solution? Does anybody know how to solve this problem? Thank you all!

Peter Pillen

I think I know how it can be fixed, but it's above my programmingskills atm.

in the virtuemart administrator backend - > configuration -> article sorting, the two dropdown menus for the standard sorting should need an additional select box with ascending and descending as an option. Then in the product.php file the ASC and DESC should be replaced with the value set in the configuration. But truly... I miss the time currently to solve it :(