Edit: This is easily my most popular post and solicits a lot of questions. This method sorts children in a table on the parent product page. It DOES NOT sort children in a drop down list. 1/10/2011
UPDATE: New methods here: I am updating with another post that will try to address how to universally sort attribute/child drop down lists.
I’ve been pulling my hair out the past couple of hours trying to find a built-in way to order child items in VirtueMart. There are plenty of ways to sort built-in to the category view of multiple products, but there is no built in function to sort child products (items). The guidance on the VirtueMart forums was lacking and would produce errors when including external child ids to be included, so I had to do some digging.
Around line 488 in ps_product_attribute I was able to add the following code after the if($child_ids){} clause:
elseif(!$child_ids){
$q .=” ORDER BY product_id”;
}
Now my child items are sorted by ID. You could easily product_id to be any other field, but for my purposes this worked great.

I have been looking for a solution for for two days now. My php is remedial, can you specify the two lines of code you placed this snippet between?
Thank You!!!
Around line 488 or so you should see:
if($child_ids){and a bunch of other code enclosed in the curly brackets and then a final}after the } bracket you should put the codeelseif(!$child_ids){$q .=” ORDER BY product_id”;
}
This will order them by product_id, but you could replace ‘product_id’ with any other field you wanted to sort by.
Bummer, didn’t work on my Joomla 1.5.12 / Virtuemart 1.1.4 platform. Although on re-reading your article I think I’m seeking a solution to a different issue: I want to be able to change the order in which child products are listed in a drop-down list of the parent product page. Appreciate the help though!
Cheers
Yeah, I’m using this to sort children products listed within a parent product page, not a drop down. I assume you can find the query that grabs the drop-down items and sort that in a similar way.
you rock .. your a genius .. your the man … your etc etc etc ..
i really appreciate your info on this. ty
Hi, could you please tell me what file you need to make this fix in? I can’t seem to figure it out.
Sure: It’s in the ps_product_attribute.php file within the administrator/components/virtuemart/classes folder.
Hi Chris,
Like Bold also stated. There are lots of us seeking a way to sort the children in a drop down list.
Can you help us out a bit…?
The solution I’ve suggested for sorting within the SQL query itself that pulls the children. There are several and each of them will change how the attributes are displayed depending on if you’re using a drop down, parent product page listing, etc. The example I’ve used is for listing a child product table on a parent product page.
All you need to do is play around until you find the SQL query that is pulling the data for the drop down list, rather than the child table.
This trick should be applied in another place in the same file ps_product_attribute.php
Around line 262 you will find:
“$q = “SELECT product_id,product_name…
after that add a new line:
$q .= “ORDER BY product_sku”;
That will sort childs by product SKU.
That worked for me.
Unfortunately this modification does not seem to work on Virtuemart 1.1.9
The code you have mentioned is already included on line 512 but when I change product_id to product_price this has no effect