VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: saiborg on January 26, 2012, 13:24:34 PM

Title: Order product by DESC
Post by: saiborg on January 26, 2012, 13:24:34 PM
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
Title: Re: Order product by DESC
Post by: TopPretender on March 14, 2012, 18:19:41 PM
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']);
}
Title: Re: Order product by DESC
Post by: slammy on April 18, 2012, 21:44:52 PM
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

Title: Re: Order product by DESC
Post by: gamecat2300 on June 14, 2012, 07:31:41 AM
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-=
Title: Re: Order product by DESC
Post by: slammy on June 14, 2012, 10:18:21 AM
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
Title: Re: Order product by DESC
Post by: FcVM on November 23, 2012, 00:18:34 AM
Does anyone know a solution ?
Title: Re: Order product by DESC
Post by: bytelord on November 23, 2012, 01:23:27 AM
Did you follow the above instructions and didn't work for you?
Title: Re: Order product by DESC
Post by: Peter Pillen on November 23, 2012, 18:50:11 PM
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 ;)
Title: Re: Order product by DESC
Post by: FcVM on November 23, 2012, 20:25:23 PM
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.
Title: Re: Order product by DESC
Post by: Peter Pillen on November 23, 2012, 22:50:34 PM
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' ;

Title: Re: Order product by DESC
Post by: FcVM on November 24, 2012, 23:02:12 PM
P2 Peter
It works. Thank you so much  :)
Title: Re: Order product by DESC
Post by: Peter Pillen on November 25, 2012, 00:03:50 AM
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  :-\
Title: Re: Order product by DESC
Post by: Peter Pillen 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
Title: Re: Order product by DESC
Post by: guidocx842 on December 11, 2012, 22:38:30 PM
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!
Title: Re: Order product by DESC
Post by: Peter Pillen on December 11, 2012, 23:45:05 PM
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 :(
Title: Re: Order product by DESC
Post by: guidocx842 on December 12, 2012, 20:10:45 PM
Quote from: P2 Peter on December 11, 2012, 23:45:05 PM
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 :(

Yes... I suppose that this feature is one of the essential things that could be integrated in next versions of virtuemart.
Title: Re: Order product by DESC
Post by: srubard on April 09, 2013, 21:07:05 PM
Hi Peter. Good job, but this solution don't work in Virtuemart 2.0.20b. Can you help me with this, please? Thank you very much. David
Title: Re: Order product by DESC
Post by: Peter Pillen on April 09, 2013, 21:21:14 PM
And what exactly doesn't work? ordering? switching from asc to desc? sef on/off? ... Because I have the same version, but in my case, it still works using the same code.

And also important:
1. is sef on or off?
2. which is the standard sorting setting in your administrator backend of virtuemart?
Title: Re: Order product by DESC
Post by: srubard on April 11, 2013, 19:58:02 PM
Hello. Can you send me your product.php? I have SEF off now, but in the future SEF will be ON. Ordering is working, but switchiching from asc to desc not. I would like default sorting by DESC. Products with more pieces in stock first and products not in stock last.
In VM backend I have Default product sort order: Product in stock.

Title: Re: Order product by DESC
Post by: Peter Pillen on April 11, 2013, 21:23:35 PM
i can't attach the product.php to this post... that type of file is not allowed as attachment  :o (maybe send me your e-mail address by in-forum-message)

the clue for your choice of ordering is searching the following line in product.php
         $q .=  $orderBy . $direction . ' LIMIT 0,' . (int)$max;

i have it set to this (because I only use product id for ordering)
         $q .= ' ORDER BY `l`.`virtuemart_product_id` ' . $direction . ' LIMIT 0,' . (int)$max;

you need to alter the virtuemart_product_id variable to the database field you want the products ordered by
Title: Re: Order product by DESC
Post by: bobchain on May 07, 2013, 15:55:44 PM
Dear Peter,
I made ​​the change that you indicated in your post, but once you have completed your changes, the default is that the button to change the sort order, returns the same order in the results.
I tried changing the type of sorting (the site must be ordered by creation date), by price, by code, but in both cases does not change.
the only difference that I noticed is that the icon that showed the first search result as asc +/- now appears as +/-, in fact now by clicking on the exchange rate arrangement appears in the url: http://www.miodominio.xxx/index.php/publications/.../.../orderAsc while first appeared "orderDesc"

What is wrong in the changes I've made​​?

thanks for your help!

P.S.:  J 2.5.8  +  VM 2.0.20a  + template custom override
Title: Re: Order product by DESC
Post by: Peter Pillen on May 07, 2013, 16:59:18 PM
you will first need to check if your creation dates are saved properly. There has been some issues with creation dates that were wrong in previous versions. An alternative way is to use de article id as sorting field because they also are chronological. Normaly clicking the +/- should change the order from descending to ascending.
Title: Re: Order product by DESC
Post by: bobchain on May 07, 2013, 17:26:55 PM
first of all thanks for your prompt reply.
I tried to change the sort order by using code and price, which in sight are much easier to follow, but the problem I found with those two settings.
the strange thing is that no changes sorting though not as I requested it works: default is "asc", and clicking on the order becomes "desc" (also appears use the orderDesc on the URL)

applying the change to the default that the order click on the button in the same way, even if the url shows "orderAsc" and the small icons appear correctly as described above.

I made ​​the change 2 times, thinking he had something wrong the first time, but the result is the same.

one thing I've noticed over the changes mentioned is that some valuations in my code on product.php strangely were already defined as DESC

where is my problem?
Title: Re: Order product by DESC
Post by: Peter Pillen on May 07, 2013, 19:09:09 PM
it is possible that my initial code is already become to old. It is possible that there already been some changes that effect behaviour of the desc/asc settings.
Title: Re: Order product by DESC
Post by: bobchain on May 08, 2013, 14:04:07 PM
Dear Peter
if so ... which could be the correct changes to my version?

Title: Re: Order product by DESC
Post by: Peter Pillen on May 08, 2013, 14:22:57 PM
I'm having problems understanding where exactly it is going wrong. Because it is strange that the code behaviour would be different in case A and case B. That makes me think there is something wrong in the data.

default sort order is set on "creation date"?
and the sort button and order is not working as expected for the creation date?

please double check your mysql database with php myadmin

table *your database prefix*_virtuemart_products and check if there are correct values in the field "created_on". There should be a date and not 0000-00-00 00:00:00.

It is actually the only problem I can think of in your case.

Title: Re: Order product by DESC
Post by: bobchain on May 08, 2013, 15:24:15 PM
Dear,
for this doubt I ran two more tests as I wrote earlier in the post, setting the "default order" as "the price of the product" and the "sku code" (more easy to check) with both the solution and the problem persisted.

by this test I realized that the problem is not in the information for which I perform sorting.

I rerun the change you indicated before, mistakenly thinking of committing the same error, but always with the same result.

if you give me an address and you have time and want to try it I can send you my file product.php (careful, however, because in the same file I have already made ​​other implementations/customizations: I have able the multiselelected manufacturer for single product)
Title: Re: Order product by DESC
Post by: bobchain on May 10, 2013, 16:15:28 PM
Quote from: bobchain on May 08, 2013, 15:24:15 PM
(careful, however, because in the same file I have already made ​​other implementations/customizations: I have able the multiselelected manufacturer for single product)
SOLVED!!!!

and luckily I have said to make sure that personalization!!
my problem was right there! your edit works perfectly Peter!
Forgive me for making you lose time in analyzing a problem that does not exist!
thank you anyway for your support!
Title: Re: Order product by DESC
Post by: Peter Pillen on May 10, 2013, 16:44:16 PM
No thanks! I was beginning to doubt my coding, but lukily all is fine now.
Title: Re: Order product by DESC
Post by: bobchain on May 10, 2013, 16:58:27 PM
this will be appreciate in the future release...
Quote from: P2 Peter on December 11, 2012, 23:45:05 PM
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.
otherwise the standard alphabetical sorting "desc" is not pleasant

Sorry again!
Title: Re: Order product by DESC
Post by: castart on May 29, 2013, 11:48:45 AM
The next code worked for me

Joomla 2.5.11, Virtuemart 2.0.20b
Joomla SEF on
Virtuemart SEO Switched on
SEO extenseion -detail D
Default article sort creation date

Near line 397   after: default;
               if (!empty($this->filter_order)) {
                  $orderBy = ' ORDER BY ' . $this->filter_order . ' ';



/* 20130529 begin code cast-art siwtch direction if order is created_on*/   
      $a=$this->filter_order;
      $b=$this->filter_order_Dir;
      
        if ($a=="`p`.created_on"&&$b=="DESC")
            {
           $this->filter_order_Dir="ASC";
           }
        else
            {
               if ($a=="`p`.created_on"&&$b=="ASC"||$filter_order=="`p`.created_on"&&$b=="")
                {
                  $this->filter_order_Dir="DESC";
            }
            }               
      /* end code cast-art */
Title: Re: Order product by DESC
Post by: slammy on August 29, 2013, 09:50:21 AM
I just installed 2.0.22b and this issue is present again. The choosing of "show latest added products first" and "creation Date" in products-sorting as a sort-possibility in vm -backend does not affect the product-category-view. Oldest added products showing up first!
Title: Re: Order product by DESC
Post by: castart on August 31, 2013, 08:30:55 AM
Even in 2.0.22a the issue is present.
So everytime you upgrade Virtuemart the extra code (core hack) is overridden.
So after every upgrade you will have to add the extra products-sorting script.
Title: Re: Order product by DESC
Post by: Milbo on September 01, 2013, 18:42:40 PM
Quote from: P2 Peter on December 11, 2012, 23:45:05 PM
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 :(

What I am just doing, prepare to test a 2.0.22c Version.
Title: Re: Order product by DESC
Post by: castart on September 02, 2013, 15:58:33 PM
OK thanks
Title: Re: Order product by DESC
Post by: system_error86 on January 10, 2017, 10:01:22 AM
Hello, I know that the thread is old but I need a litle help. I would like to have in only one gategory ASC ordering and in other categories I want to have DESC ordering. I am trying to put an if statement in the line 148 for me
         if ($virtuemart_category_id = 202){
               $filter_order_Dir = strtoupper (JRequest::getWord ('order', 'ASC'));
               $valid_search_fields = VmConfig::get ('browse_search_fields');   
            }else {
                                        $filter_order_Dir = strtoupper (JRequest::getWord ('order', 'DESC'));
               $valid_search_fields = VmConfig::get ('browse_search_fields');   }

but it is not working.I have the 2.0.15a version of virtuemart and the joomla is 2.5.14. Can you help me please??
Thanks a lot

Title: Re: Order product by DESC
Post by: jenkinhill on January 10, 2017, 11:47:37 AM
Quote from: system_error86 on January 10, 2017, 10:01:22 AM
I have the 2.0.15a version of virtuemart and the joomla is 2.5.14.

Not only an old thead, but ancient and insecure VirtueMart and Joomla versions! Could you not update to current J3 VM3 versions?
http://forum.virtuemart.net/index.php?topic=118683.0

Using current versions also makes it more likely that someone can help.
Title: Re: Order product by DESC
Post by: system_error86 on January 10, 2017, 12:32:08 PM
I cannot do updates. It has many core changes in the code.
If anyone can help I would apriciate.
Thanks a lot
Title: Re: Order product by DESC
Post by: castart on January 10, 2017, 13:49:54 PM
Maybe helpful to echo the values of the fields you use to find out whether you use the right fields.

I agree with jenkinhill. You'd better update for in future more problems wil arise.