VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: rvbgnu on December 03, 2012, 21:55:11 PM

Title: Product sort order on browse/category view - ascending to descending
Post by: rvbgnu on December 03, 2012, 21:55:11 PM
Hi,

I have looked at some part of the code, but cannot find where to change the product order from ASCending to DESCending. I setup of course the Admin > VirtueMart > Configuration > Configuration > Product Order Settings, and then change "Default product sort order" to "Creation Date". That's fine. But I would like to have the latest products first, so I supposed it is the most recent "creation date" setting. But in the config I cannot change the order from ascending (The less recent first) to Descending.

I think it should be default descending, but any way, where can I change it?

No problem if it is a hack, I am maintaining a Git repository, so I can keep track of the change with the next Vm releases.
Title: Re: Product sort order on browse/category view - ascending to descending
Post by: aksatob on December 04, 2012, 02:43:28 AM
Hello,

i am not sure that this is exactly what you want... but i had similar problem (i want to sort products shown in  - module virtuemart product) In my case i need to change order only in that module, so i cant change order in administration, so i wrote small function "hack" to do it.

There is one condition - its sort array of products, so it can be used only there, where VM generate product array itself
(for example before "foreach $products as $product" ... )

//$products_to_sort=array of product to sort
//$dir - way how to sort SORT_ASC or SORT_DESC
//$value- "what sort" (product_name,virtuemart_product_id,product_sku,prices..ect

function sort_products_by_value(&$products_to_sort, $dir, $value) {
    $sort_col = array();
   foreach ($products_to_sort as $product) {
   
   }
   
    foreach ($products_to_sort as $key=> $row) {
        $sort_col[$key] = $row->$value;
   
   }
     
    array_multisort($sort_col, $dir, $products_to_sort);
}
//end sort funct. declaration 

BTW: $value in your case should be 'created_on' .. i guess :)

BTW: i am noob in php stuff , so i think that somebody give you better solution, but i meantime, you can try it :)

(second option which probably should work is edit default order setting in SQL selections in  administrator/components/com_virtuemart/models/product.php  - DEC to ASC, but..... :)

Title: Re: Product sort order on browse/category view - ascending to descending
Post by: rvbgnu on December 04, 2012, 10:55:55 AM
Hi aksatob,

Thank you for your reply. This is not exactly what I am looking for, because it is not in product module, but in the product  category view (browse) that I am looking for changing the sort order.
Good to know for someone looking for changing the module view  :D
Title: Re: Product sort order on browse/category view - ascending to descending
Post by: aksatob on December 04, 2012, 16:09:22 PM
hmmm, so its in product list in category view?

i think that is the same :) override default.php in components\com_virtuemart\views\category\tmpl

line 209_210:

// Start the Output
   foreach ($this->products as $product) {

so if you sort array "$this->products" before "foreach" loop it should do exactly what you wants to do.. i guess..

sort function which i post before should do that job for you (i dint test it..)

anyway there should be definitely some easier "official" way how to do it, in fact - we have sort options buttons in right corner of category view so change default order should be possible, but i am not using category view so i don't have experience with it...
Title: Re: Product sort order on browse/category view - ascending to descending
Post by: rvbgnu on December 04, 2012, 18:02:45 PM
Actually, it should work>
But I am looking at administrator/components/com_virtuemart/models/product.php again, and there is some possibilities here.
Then I just seen that MOST of the products have no initialised "Created_on" filed (all the row in the database in at "0000-00-00 00:00:00" value). Which make it quite useless for my idea now...

So I am using "Ordering", and sorting manually products in every category. TEMPO solution, because the navigation(neighbour function) is buggy as well.

Anyone has ever looked into these complex db requests?
Title: Re: Product sort order on browse/category view - ascending to descending
Post by: kaybee57 on December 20, 2012, 06:33:00 AM
Same as rvbgnu - I wish to sort products in decending order of creation date on the front end category view - did you come up with a solution??
Title: Re: Product sort order on browse/category view - ascending to descending
Post by: Peter Pillen on December 20, 2012, 10:32:15 AM
checkout topic http://forum.virtuemart.net/index.php?topic=97045.0 (http://forum.virtuemart.net/index.php?topic=97045.0)

also in combination with this one

http://forum.virtuemart.net/index.php?topic=101208.0 (http://forum.virtuemart.net/index.php?topic=101208.0)
Title: Re: Product sort order on browse/category view - ascending to descending
Post by: fx3000 on March 06, 2013, 23:37:23 PM
find administrator/components/com_virtuemart/models/product.php
line 145 (vm 2.0.18)
$filter_order_Dir = strtoupper (JRequest::getWord ('order', 'DESC'));
or
$filter_order_Dir = strtoupper (JRequest::getWord ('order', 'ASC'));

read : http://forum.virtuemart.net/index.php?topic=97045.0
Title: Re: Product sort order on browse/category view - ascending to descending
Post by: lostmail on June 13, 2013, 16:05:22 PM
Sort order of (Sub)-Categories ist wrong:

Configuration of Categories ist set to "category name".....but it does not sort correct...

[attachment cleanup by admin]
Title: Re: Product sort order on browse/category view - ascending to descending
Post by: diverso on September 30, 2013, 09:10:39 AM
Quote from: aksatob on December 04, 2012, 16:09:22 PM
hmmm, so its in product list in category view?

i think that is the same :) override default.php in components\com_virtuemart\views\category\tmpl

line 209_210:

// Start the Output
   foreach ($this->products as $product) {

so if you sort array "$this->products" before "foreach" loop it should do exactly what you wants to do.. i guess..

sort function which i post before should do that job for you (i dint test it..)

anyway there should be definitely some easier "official" way how to do it, in fact - we have sort options buttons in right corner of category view so change default order should be possible, but i am not using category view so i don't have experience with it...

Having same issue here. did you test this? don+t understand exactly what you mean by "sort array "$this->products" before "foreach" loop" can you please be more specific on how to tweak the code.
Title: Re: Product sort order on browse/category view - ascending to descending
Post by: Maxim Pishnyak on October 03, 2013, 15:41:57 PM
http://forum.virtuemart.net/index.php?topic=79799