VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: roycosoep on September 28, 2012, 09:38:41 AM

Title: Stockable variants: sorting order of child products in dropdown box
Post by: roycosoep on September 28, 2012, 09:38:41 AM
Hello,

I have a question about the sorting order of child products that belong to a certain parent product. For example:
In this case, when selecting the parent product in the webshop, I get the three options (S, M, L) to choose from in a drop-down box. However, the order of these options is alphabetically (L, M, S) where I would like it to be (S, M, L). In the custom field options the correct order of possible values is stated (S, M, L).

How can I fix this?

Thanks a lot in advance!

Regards,
Roy
Title: Re: Stockable variants: sorting order of child products in dropdown box
Post by: delliott on October 23, 2012, 22:58:30 PM
I need to know the answer to this question too.  I've been diving through code trying to find the correct WHERE clause to force the order and cannot find anything that seems to work.  Order seems to be random at best.  Will someone at Virtuemart please respond to this thread?
Title: Re: Stockable variants: sorting order of child products in dropdown box
Post by: delliott on October 23, 2012, 23:14:59 PM
Of course as soon as I post the question, then I stumble on the answer.

Line # 2038 of administrator/com_virtuemart/models/product.php, change the ORDER BY clause to look like below.  The order of the drop-down will now look to the product SKU values for ordering instructions.

         $q .= ' GROUP BY `virtuemart_product_id` ORDER BY virtuemart_product_id, p.product_sku';
Title: Re: Stockable variants: sorting order of child products in dropdown box
Post by: bmw2182 on October 24, 2012, 02:50:00 AM
I changed line 2038 in /administrator/components/com_virtuemart/models/product.php

to         
$q .= ' GROUP BY `virtuemart_product_id` ORDER BY virtuemart_product_id, p.product_sku';

and commented out the next line
//$q .= ' GROUP BY `virtuemart_product_id` ORDER BY ordering DESC';

however, it didn't seem to work for me.  I'm sure I'm missing something.

I have attached a print screen of how I have it setup on the main product as well as how it shows up.  I want it to be ordered from lowest to highest.......

Any thoughts??? What am I missing?

[attachment cleanup by admin]
Title: Re: Stockable variants: sorting order of child products in dropdown box
Post by: onnj on October 24, 2012, 04:08:17 AM
What I did here is I set weight to small, medium and large by .5kg, 1kg and 1.5 kg.

and at the custom field try to select not by product sku but by product weight my problem now is to some product this will work it will show s, m, l ... but to some product still s, l, m.... small is my parent product and m,l are the child product
Title: Re: Stockable variants: sorting order of child products in dropdown box
Post by: jike1985 on November 03, 2012, 14:33:23 PM
Thanks for the solution on this - you've saved me many hours of googling!!
Title: Re: Stockable variants: sorting order of child products in dropdown box
Post by: kovacshazi on April 30, 2014, 19:52:55 PM
VM2.0.26d and J2.5.19

Quote from: delliott on October 23, 2012, 23:14:59 PM
Of course as soon as I post the question, then I stumble on the answer.

Line # 2038 of administrator/com_virtuemart/models/product.php, change the ORDER BY clause to look like below.  The order of the drop-down will now look to the product SKU values for ordering instructions.

         $q .= ' GROUP BY `virtuemart_product_id` ORDER BY virtuemart_product_id, p.product_sku';
I would like to sort the items to stock, but unfortunately this solution does not help. Does anyone have any ideas?
I changed the code to p.product_in_stock