Magento: Filter Configurable Product by their options

Magento: Filter Configurable Product by their options

October 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Filter Configurable Product by their options

Filtering Magento Configurable Products by Their Option Attributes

In Magento, configurable products allow you to combine multiple attributes like size, color, or designer to create a variety of product options. However, filtering these products based on the attributes assigned to their child instances can be a challenge. This post will guide you through the process of filtering configurable products by attributes that are not directly associated with the main product but rather with its children.

The Current Filtering Approach

The provided code snippet demonstrates an attempt to filter products by designer, color, and size attributes:

$attributes_designers = $this->getRequest()->getParam('designers');
$attributes_colors = $this->getRequest()->getParam('color');
$attributes_sizes = $this->getRequest()->getParam('size');

$_productCollection = $currentCategory->getProductCollection();

if (count($attributes_designers) > 0 && !in_array("ALL", $attributes_designers)) {
    $_productCollection->addAttributeToFilter('designer', $attributes_designers);
}
// Similar conditions for color and size

While this approach works well for attributes directly assigned to the main product, it fails when using attributes like color or size_apparel_eu, as they are not directly associated with the parent configurable product. These attributes are instead assigned to the child simple products that make up the configurable product.

Filtering by Child Product Attributes

To filter configurable products based on their option attributes, we need to adjust our approach:

  1. Select the Simple Products: First, let’s select all the simple products associated with the configurable products in the current category.
$_productCollection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', array('eq' => 'simple'))
    ->joinField('parent_id', 'catalog/product_super_link', 'product_id', 'entity_id="child_id"', null, 'left');
  1. Add Attribute Filter: Now that we have the simple products, we can add a filter for the desired attribute.
if (count($attributes_colors) > 0 && !in_array("ALL", $attributes_colors)) {
    $_productCollection->addAttributeToFilter('color', $attributes_colors);
}
  1. Distinct Configurable Parent IDs: To get only the distinct configurable parent IDs, we use the distinct condition.
$_productCollection->getSelect()->distinct(true)->group('parent_id');
  1. Join and Load Products: Finally, join with the main product collection and load the products.
$_productCollection->joinField('entity_id', 'catalog/product', 'entity_id', 'entity_id=parent_id', null, 'left')
    ->load();

Conclusion

Filtering Magento configurable products by option attributes requires a different approach than filtering by direct product attributes. By selecting the simple child products and then filtering them based on the desired attribute, we can effectively filter configurable products by their option attributes.

Remember to clear your cache after making these changes, as Magento uses cached data for collections.

Learn more about advanced Magento filtering techniques in our comprehensive guide.

Catalog Configuration

Our network