Author Topic: Order product by DESC  (Read 20988 times)

saiborg

  • Beginner
  • *
  • Posts: 3
Order product by DESC
« 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

TopPretender

  • Beginner
  • *
  • Posts: 15
Re: Order product by DESC
« Reply #1 on: March 14, 2012, 18:19:41 pm »
change file: /administrator/components/com_virtuemart/models/product.php
Find the following code:
Code: [Select]
/* 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:
Code: [Select]
if ( isset($query['order']) ) {
if ($query['order'] =='DESC') $segments[] = $helper->lang('orderDesc') ;
unset($query['order']);
}
to after
Code: [Select]
if ( isset($query['orderby']) ) {
$segments[] = $helper->lang('by').','.$helper->lang( $query['orderby']) ;
unset($query['orderby']);
}

slammy

  • Jr. Member
  • **
  • Posts: 169
  • vm supporter member
  • VirtueMart Version: vm 3.0.x and jml 3.4.5
Re: Order product by DESC
« Reply #2 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:

Code: [Select]
        /* 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

  • Jr. Member
  • **
  • Posts: 52
Re: Order product by DESC
« Reply #3 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-=

slammy

  • Jr. Member
  • **
  • Posts: 169
  • vm supporter member
  • VirtueMart Version: vm 3.0.x and jml 3.4.5
Re: Order product by DESC
« Reply #4 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

FcVM

  • Beginner
  • *
  • Posts: 3
Re: Order product by DESC
« Reply #5 on: November 23, 2012, 00:18:34 am »
Does anyone know a solution ?

bytelord

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: Order product by DESC
« Reply #6 on: November 23, 2012, 01:23:27 am »
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

  • Jr. Member
  • **
  • Posts: 223
Re: Order product by DESC
« Reply #7 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)
Code: [Select]
$filter_order_Dir = strtoupper (JRequest::getWord ('order', 'ASC'));
change that to
Code: [Select]
$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

  • Beginner
  • *
  • Posts: 3
Re: Order product by DESC
« Reply #8 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:
Code: [Select]
/* 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

  • Jr. Member
  • **
  • Posts: 223
Re: Order product by DESC
« Reply #9 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
Code: [Select]
var $filter_order_Dir = 'ASC';change ASC to DESC

approximatly @ line 115
Code: [Select]
$this->filter_order_Dir = 'ASC';change ASC to DESC

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

approximatly @ line 1749
Code: [Select]
$order = JRequest::getWord ('order', 'ASC');
if ($order == 'DESC') {
$orderTxt .= '&order=' . $order;
}
change to
Code: [Select]
$order = JRequest::getWord ('order', 'DESC');
if ($order == 'ASC') {
$orderTxt .= '&order=' . $order;
}

approximatly @ line 1857
Code: [Select]
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
Code: [Select]
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
Code: [Select]
if ($query['order'] =='DESC') $segments[] = $helper->lang('orderDesc') ;change to
Code: [Select]
if ($query['order'] =='ASC') $segments[] = $helper->lang('orderAsc') ;
approximatly @ line 358
Code: [Select]
if (  $helper->compareKey(end($segments),'orderDesc') ){
//$vars['order'] ='DESC'
change to
Code: [Select]
if (  $helper->compareKey(end($segments),'orderAsc') ){
$vars['order'] ='ASC' ;

FcVM

  • Beginner
  • *
  • Posts: 3
Re: Order product by DESC
« Reply #10 on: November 24, 2012, 23:02:12 pm »
P2 Peter
It works. Thank you so much  :)

Peter Pillen

  • Jr. Member
  • **
  • Posts: 223
Re: Order product by DESC
« Reply #11 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  :-\

Peter Pillen

  • Jr. Member
  • **
  • Posts: 223
Re: Order product by DESC
« Reply #12 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

guidocx842

  • Jr. Member
  • **
  • Posts: 74
Re: Order product by DESC
« Reply #13 on: December 11, 2012, 22:38:30 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

  • Jr. Member
  • **
  • Posts: 223
Re: Order product by DESC
« Reply #14 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 :(