2

Scenario:

A store catalog is populated with configurable products each having several children with different sizes and colors. As the goal is to show the different color variations, only the children's visibility is set to Catalog, Search while the configurable parents' visibility is set to Not Visible Individually.

Issue:

The catalog is currently showing every size variations for each color when ideally only a single variation per color should be showing.

Attempted Solution:

A unique attribute based on both the configurable parent SKU and color was created.

$collection->getSelect()->group($attribute);

This solution would be working correctly on a flat collection grouping, however it can cause conflicts with the different aliases used within EAV collection queries.

2

There is a built in Magento function to group an EAV collection by a specific attribute:

Mage_Eav_Model_Entity_Collection_Abstract::groupByAttribute($attribute)

It can be used on the collection directly as follow:

$collection->groupByAttribute($attribute);

Important Notes:

This ensures that the correct aliases will be used throughout the query as the function has been developed in a way that it is reusing the same field names. At the opposite using group() directly on the select object where the query contains aliases can cause conflicts if the query end up manipulated before the collection is loaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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