I have an issue which I'm not able to find a solution here and is how to sort all the associated products of a grouped product automatically for every grouped product in the store?

I have 1850 grouped products with their associates but I want to sort these associated products by price from the cheapest to the most expensive. (Up to down)

Anyone know how to do this?


2 Answers 2


There are two ways to achieve this.

  1. Rewrite the method responsible for creating grouped product association. This saves the positioning in the DB.

For #1, you will need to look at Mage_Catalog_Model_Resource_Product_Link::saveProductLinks. Essentially, in the foreach ($attributes as $attributeInfo) loop of this method, one of the iterations will be for the catalog_product_link_attribute_int table, which hold the positions under the column value when product_link_attribute_id = 2.

You'll need to somehow retrieve the product prices and use that as the sorting index. I recommend pre-loading them into an easily accessible array, so that all you need to do is load it once and access it during the entire save.

  1. Sort on-the-fly when the products get rendered on the frontend. This does not save the positions.

This is easier but slower and only superficial. You'll just need to find the block responsible for rendering the group products and sort the collection or array of products.

I recommend #1 and it's pretty straightforward once you understand the method saveProductLinks.

  • It's possible to see an example? I understand the process but I'm very newbie in Magento and I don't know how to do it...
    – Joanmacat
    Commented Mar 17, 2015 at 16:57
  • Well.. do you know PHP? The example would be more or less the whole code, and I prefer answering specific questions that demand snippets of code. If you have specific questions along the way, I can help answer those smaller parts. Check out my profile, if you want to contact me directly (@admin, not sure if it's frown upon, but please let me know if it is).
    – laketuna
    Commented Mar 17, 2015 at 17:25
  • Ok thank you, I'll try to work with your first answer because I think is the better solution too.
    – Joanmacat
    Commented Mar 18, 2015 at 14:40
  • Yeah, give it a shot, and post an update if you still have problems.
    – laketuna
    Commented Mar 18, 2015 at 14:44

I finally found something different that in my case works too and it's easier but maybe could work temporally while you are finding a better method.

You need to check this file:


And find the function

getAssociatedProducts($product = null) {}

Then only you need to add a ->setOrder('price', 'ASC') in $collection variable.

Looks like this:

 $collection = $this->getAssociatedProductCollection($product)
                ->addAttributeToFilter('status', array('in' => $this->getStatusFilters($product)));

Flush caches and check the grouped products.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.