1

Well, I'm having a category filled only with grouped products and I want these ones to be filtered by their associated ( and simple ) products's attributes.

Until now I've used a dirty workaround : I've left only one simple product to be visible to catalog but hidden by html & css.
That way the attributes were appearing and I could use them for the grouped products also, but I've noticed that layered navigation dissapears if that hidden simple product is not appearing when I filter by price.

Any ideas or workarounds?

Thanks.

1 Answer 1

1

You need to rewrite how Mage_Catalog_Model_Layer builds the attribute collection using the current product collection's attribute sets:

protected function _getSetIds()
{
    $key = $this->getStateKey().'_SET_IDS';
    $setIds = $this->getAggregator()->getCacheData($key);

    if ($setIds === null) {
        $setIds = $this->getProductCollection()->getSetIds();
        $this->getAggregator()->saveCacheData($setIds, $key, $this->getStateTags());
    }

    return $setIds;
}

For this context, you'll want to check the product collection for grouped products and return the attribute set IDs of grouped children. These are then evaluated in getFilterableAttributes():

public function getFilterableAttributes()
{
    $setIds = $this->_getSetIds();
    if (!$setIds) {
        return array();
    }
    /** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
    $collection = Mage::getResourceModel('catalog/product_attribute_collection');
    $collection
        ->setItemObjectClass('catalog/resource_eav_attribute')
        ->setAttributeSetFilter($setIds)
        ->addStoreLabel(Mage::app()->getStore()->getId())
        ->setOrder('position', 'ASC');
    $collection = $this->_prepareAttributeCollection($collection);
    $collection->load();

    return $collection;
}

You will likely need to deal with the cache key. I would develop with block caching off and then test extensively with it on.

2
  • Thanks for answering my question. I will try your workaround in a couple of days and I'll get back to you with some news. Sep 21, 2013 at 21:38
  • Thanks a lot. I've made a simple check with Mage::registry('current_category'); and then I've just edited the getSetIds variable. But how could I automate the process and apply the same method for all categories and search page also? I can't loop through all getProductCollection() because there are lots of products, simple and grouped, from different categories. Any advices? Oct 18, 2013 at 5:19

Your Answer

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

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