Ordering VirtueMart Child Items

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.

Be Sociable, Share!