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?
Best Answer
There are two ways to achieve this.
For #1, you will need to look at
Mage_Catalog_Model_Resource_Product_Link::saveProductLinks
. Essentially, in theforeach ($attributes as $attributeInfo)
loop of this method, one of the iterations will be for thecatalog_product_link_attribute_int
table, which hold the positions under the columnvalue
whenproduct_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.
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
.