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

Product sort order on browse/category view - ascending to descending

Started by rvbgnu, December 03, 2012, 21:55:11 PM

Previous topic - Next topic

rvbgnu

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.
Best Regards, Hervé Boinnard - Irish Time (GMT)
Joomla! multilingual website and online business made easy - https://www.puma-it.ie

3D Secure v1 (3DS1) & Strong Customer Authentication (SCA)! Stripe.com payment plugin for VirtueMart 3: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/stripe-for-virtuemart
Authipay (AIB Merchant Services) for VirtueMart 2 & 3: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/authipay-aib-merchant-services-for-virtuemart

aksatob

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..... :)


rvbgnu

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
Best Regards, Hervé Boinnard - Irish Time (GMT)
Joomla! multilingual website and online business made easy - https://www.puma-it.ie

3D Secure v1 (3DS1) & Strong Customer Authentication (SCA)! Stripe.com payment plugin for VirtueMart 3: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/stripe-for-virtuemart
Authipay (AIB Merchant Services) for VirtueMart 2 & 3: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/authipay-aib-merchant-services-for-virtuemart

aksatob

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...

rvbgnu

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?
Best Regards, Hervé Boinnard - Irish Time (GMT)
Joomla! multilingual website and online business made easy - https://www.puma-it.ie

3D Secure v1 (3DS1) & Strong Customer Authentication (SCA)! Stripe.com payment plugin for VirtueMart 3: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/stripe-for-virtuemart
Authipay (AIB Merchant Services) for VirtueMart 2 & 3: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/authipay-aib-merchant-services-for-virtuemart

kaybee57

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??


fx3000

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

lostmail

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]
VirtueMart VirtueMart 4.2.16 11030 | Joomla 4.x | PHP 8.3 | Vp_neoteric 1.6

diverso

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.