I am trying to get filterable attributes of product collection after applying filter to it programmatically.

same as layered navigation idea after I apply filter to category, it just return attributes that I can filter with it. that's what I am trying to do here.

I need that to return filterable attributes after applying filter to collection to send it to mobile app via api.

$category = Mage::getModel('catalog/category')->setStoreId(1)->load(84);
$collection = $category->getProductCollection()
                        ->setOrder('position', 'ASC')
                        ->addAttributeToFilter('status', 1)
                        ->addAttributeToFilter('visibility', 4)

$filtringAttributes = Array
    (object) array
            'label' => 'Ref Nav Doors',
            'code' => 'ref_nav_doors',
            'value' => 693

    (object) array
            'label' => 'Color',
            'code' => 'color',
            'value' => 5

if (!empty($filtringAttributes)) {

    foreach ($filtringAttributes as $attribute) {
        $key = $attribute->code;
        $value = $attribute->value;
        $collection->addAttributeToFilter($key, $value);
  • What is the result of your code?
    – mtr.web
    Oct 26 '18 at 18:37
  • My code just filtering products collection using attributes and return filtered collection.. i want to get filterable attributes from this collection
    – Mo Darwish
    Oct 26 '18 at 19:06
  • You want to return the attributes that it is filtered by, or all possible attributes to filter with?
    – mtr.web
    Oct 26 '18 at 19:32
  • I already have the attributes that it is filtered by & i want all possible attributes that i can filter with.
    – Mo Darwish
    Oct 26 '18 at 20:05

I am not sure if this fits your needs exactly, but it will give you all of the columns added by your addAttributeToSelect('*') function, and all of those will be filterable in the collection.

$first = $collection

$columns = array_keys($first);

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.