2

I have been trying to write rest api to retrieve available filters of particular category by its ID.

I have a category which has two filters price and brands.

Both price and brands are visible in frontend. I can filter products by either price or brand from frontend.

I wanted to get available filters of this category in my rest request. But unfortunately my code is not working. This code returns null.

When i browse the url on browser i get desired result

But this code returns empty on both postman and private window.

I think this is happening due to session. how do i resolve this?

<?php


class BAR_Restapi_Model_Api2_Filterlist_Rest_Admin_V1 extends BAR_Restapi_Model_Api2_Filterlist_Filterlist
{


    /**
     * Retrieve filter by category ID
     *
     * 
     */
    protected function _retrieve()
    {

    $layer = Mage::getModel("catalog/layer");

    //category_id=112
    $category = Mage::getModel("catalog/category")->load(112);
    $layer->setCurrentCategory($category);
    $attributes = $layer->getFilterableAttributes();

    foreach ($attributes as $attribute) {
        if ($attribute->getAttributeCode() == 'price') {
            $filterBlockName = 'catalog/layer_filter_price';
        } elseif ($attribute->getBackendType() == 'decimal') {
            $filterBlockName = 'catalog/layer_filter_decimal';
        } else {
            $filterBlockName = 'catalog/layer_filter_attribute';
        }

        $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
        echo "<br/><br/>";
        echo $attribute->getAttributeCode();
        echo "<br/>";
        foreach($result->getItems() as $option) {
            echo $option->getLabel().'<br/>';
            echo $option->getValue();

        }
}

  }     




}

How do i get available filter of a particular category by its Id?

  • did you found any solution? – xanka Sep 12 '18 at 3:34

Your Answer

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

Browse other questions tagged or ask your own question.