0

For our API we have an option to use filters, these work great so far and are pretty simply made with the addAttributeToFilter function.
However, the problem is that when a configurable product has a child product with an attribute which indicates that it's blue, and I filter the products on the color attribute with the corresponding blue filter value, it also filters out that configurable product.
We'd like to have these configurable products in our response, but how? I've seen suggestions to use addFieldToFilter, but that gives the same results.

2
  • So, you want to have both the child product and parent(configurable) product available after applying filtering.. right?
    – Mr_Green
    Commented May 3, 2014 at 12:48
  • @Mr_Green Yes, and I want the filter to look 'inside' configurable products to see if it matches one of the available child products Commented May 5, 2014 at 7:58

1 Answer 1

1

If the child products you are mentioning are simple products then you can do the following:

Include this function:

public function getConfigurableProductsFromSimple($filteredProducts){
    $configurableProducts = new array();
    foreach($filteredProducts as $simpleProduct){
        $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
                     ->getParentIdsByChild($simpleProduct->getId());
        $parentId = $parentId[0];
        $configurableProducts[] = Mage::getModel('catalog/product')->load($parentId);
    }
    return $configurableProducts;
}

and then change your filtered products something like this:

$filteredProducts = $this->getConfigurableProductsFromSimple($filteredProducts);
1
  • The issue with this is that the total product count of the collection would not be correct any more and the API call could become very slow Commented Dec 22, 2015 at 14:43

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.