Get empty result when trying to get filterable attribute for particular category The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)create new product attribute returns fault code 104 (Incorrect attribute type)Proper Mobile API Implementation for Magento?Bespoke attribute filters for each category pagesHow to hide a custom attribute to category on particular category level?SOAP fault when trying to call API for third party moduleHow to get list of all the groups of particular attribute set using Soap API?How to add a custom page with cross-sell productsTrying to get custom product attributeRestrict a controller HTTP Request by Cutomer email and password?How to get all products collection for special category

Match Roman Numerals

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?

The following signatures were invalid: EXPKEYSIG 1397BC53640DB551

How are presidential pardons supposed to be used?

Is there a writing software that you can sort scenes like slides in PowerPoint?

Would an alien lifeform be able to achieve space travel if lacking in vision?

Why not take a picture of a closer black hole?

How do I add random spotting to the same face in cycles?

Can smartphones with the same camera sensor have different image quality?

How does this infinite series simplify to an integral?

How should I replace vector<uint8_t>::const_iterator in an API?

Did God make two great lights or did He make the great light two?

Is this wall load bearing? Blueprints and photos attached

Simulating Exploding Dice

Am I ethically obligated to go into work on an off day if the reason is sudden?

I could not break this equation. Please help me

When did F become S in typeography, and why?

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Didn't get enough time to take a Coding Test - what to do now?

Change bounding box of math glyphs in LuaTeX

Arduino Pro Micro - switch off LEDs

How to delete random line from file using Unix command?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

A pet rabbit called Belle



Get empty result when trying to get filterable attribute for particular category



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)create new product attribute returns fault code 104 (Incorrect attribute type)Proper Mobile API Implementation for Magento?Bespoke attribute filters for each category pagesHow to hide a custom attribute to category on particular category level?SOAP fault when trying to call API for third party moduleHow to get list of all the groups of particular attribute set using Soap API?How to add a custom page with cross-sell productsTrying to get custom product attributeRestrict a controller HTTP Request by Cutomer email and password?How to get all products collection for special category



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








7















I need to retrieve all filterable attributes for category. I'm using that snippet:



$category = Mage::getModel('catalog/category')->load($categoryId);

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

$layer->setCurrentCategory($category);

$attributes = $layer->getFilterableAttributes();//$attributes now is empty array


Category has product with filterable attributes, also in categories options anchor was enabled. This code using in SOAP API.



Maybe someone know where I made mistake?










share|improve this question
















bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Try to var_dump($category) to see if everything is okay in general.

    – michael
    Jan 1 '15 at 15:43











  • You might asking the same thing here stackoverflow.com/questions/3157799/…

    – Sukeshini
    Jan 1 '15 at 16:36











  • I can't use var_dump because it's code for api and it return only values defined in wsdl.xml file. But I check category by pass it to one of this value. Category model is OK, and it seting to layer correct, and I can get it back by $layer->getCurrentCategory();P

    – Quickerz
    Jan 1 '15 at 16:44












  • You can try to add Mage::log($collection->getSelect(), Zend_Log::INFO, 'blah.log', true); in app/code/core/Mage/Catalog/Model/Layer.php -> public function getFilterableAttributes() before return and to run logged SQL query directly in the database or to compare it with the SQL query that is logged when you open the category through the site.

    – michael
    Jan 2 '15 at 10:22











  • getFilterableAttributes() return empty array because $setIds = $this->_getSetIds() return empty array. It happen because $this->getProductCollection() return empty collection. Maybe something else needed fo $layer to get product collection from it?

    – Quickerz
    Jan 5 '15 at 7:24


















7















I need to retrieve all filterable attributes for category. I'm using that snippet:



$category = Mage::getModel('catalog/category')->load($categoryId);

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

$layer->setCurrentCategory($category);

$attributes = $layer->getFilterableAttributes();//$attributes now is empty array


Category has product with filterable attributes, also in categories options anchor was enabled. This code using in SOAP API.



Maybe someone know where I made mistake?










share|improve this question
















bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Try to var_dump($category) to see if everything is okay in general.

    – michael
    Jan 1 '15 at 15:43











  • You might asking the same thing here stackoverflow.com/questions/3157799/…

    – Sukeshini
    Jan 1 '15 at 16:36











  • I can't use var_dump because it's code for api and it return only values defined in wsdl.xml file. But I check category by pass it to one of this value. Category model is OK, and it seting to layer correct, and I can get it back by $layer->getCurrentCategory();P

    – Quickerz
    Jan 1 '15 at 16:44












  • You can try to add Mage::log($collection->getSelect(), Zend_Log::INFO, 'blah.log', true); in app/code/core/Mage/Catalog/Model/Layer.php -> public function getFilterableAttributes() before return and to run logged SQL query directly in the database or to compare it with the SQL query that is logged when you open the category through the site.

    – michael
    Jan 2 '15 at 10:22











  • getFilterableAttributes() return empty array because $setIds = $this->_getSetIds() return empty array. It happen because $this->getProductCollection() return empty collection. Maybe something else needed fo $layer to get product collection from it?

    – Quickerz
    Jan 5 '15 at 7:24














7












7








7








I need to retrieve all filterable attributes for category. I'm using that snippet:



$category = Mage::getModel('catalog/category')->load($categoryId);

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

$layer->setCurrentCategory($category);

$attributes = $layer->getFilterableAttributes();//$attributes now is empty array


Category has product with filterable attributes, also in categories options anchor was enabled. This code using in SOAP API.



Maybe someone know where I made mistake?










share|improve this question
















I need to retrieve all filterable attributes for category. I'm using that snippet:



$category = Mage::getModel('catalog/category')->load($categoryId);

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

$layer->setCurrentCategory($category);

$attributes = $layer->getFilterableAttributes();//$attributes now is empty array


Category has product with filterable attributes, also in categories options anchor was enabled. This code using in SOAP API.



Maybe someone know where I made mistake?







magento-1 filter soap layer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 1 '18 at 6:21









Hitesh

1,2931423




1,2931423










asked Jan 1 '15 at 15:22









QuickerzQuickerz

361




361





bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 2 days ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Try to var_dump($category) to see if everything is okay in general.

    – michael
    Jan 1 '15 at 15:43











  • You might asking the same thing here stackoverflow.com/questions/3157799/…

    – Sukeshini
    Jan 1 '15 at 16:36











  • I can't use var_dump because it's code for api and it return only values defined in wsdl.xml file. But I check category by pass it to one of this value. Category model is OK, and it seting to layer correct, and I can get it back by $layer->getCurrentCategory();P

    – Quickerz
    Jan 1 '15 at 16:44












  • You can try to add Mage::log($collection->getSelect(), Zend_Log::INFO, 'blah.log', true); in app/code/core/Mage/Catalog/Model/Layer.php -> public function getFilterableAttributes() before return and to run logged SQL query directly in the database or to compare it with the SQL query that is logged when you open the category through the site.

    – michael
    Jan 2 '15 at 10:22











  • getFilterableAttributes() return empty array because $setIds = $this->_getSetIds() return empty array. It happen because $this->getProductCollection() return empty collection. Maybe something else needed fo $layer to get product collection from it?

    – Quickerz
    Jan 5 '15 at 7:24


















  • Try to var_dump($category) to see if everything is okay in general.

    – michael
    Jan 1 '15 at 15:43











  • You might asking the same thing here stackoverflow.com/questions/3157799/…

    – Sukeshini
    Jan 1 '15 at 16:36











  • I can't use var_dump because it's code for api and it return only values defined in wsdl.xml file. But I check category by pass it to one of this value. Category model is OK, and it seting to layer correct, and I can get it back by $layer->getCurrentCategory();P

    – Quickerz
    Jan 1 '15 at 16:44












  • You can try to add Mage::log($collection->getSelect(), Zend_Log::INFO, 'blah.log', true); in app/code/core/Mage/Catalog/Model/Layer.php -> public function getFilterableAttributes() before return and to run logged SQL query directly in the database or to compare it with the SQL query that is logged when you open the category through the site.

    – michael
    Jan 2 '15 at 10:22











  • getFilterableAttributes() return empty array because $setIds = $this->_getSetIds() return empty array. It happen because $this->getProductCollection() return empty collection. Maybe something else needed fo $layer to get product collection from it?

    – Quickerz
    Jan 5 '15 at 7:24

















Try to var_dump($category) to see if everything is okay in general.

– michael
Jan 1 '15 at 15:43





Try to var_dump($category) to see if everything is okay in general.

– michael
Jan 1 '15 at 15:43













You might asking the same thing here stackoverflow.com/questions/3157799/…

– Sukeshini
Jan 1 '15 at 16:36





You might asking the same thing here stackoverflow.com/questions/3157799/…

– Sukeshini
Jan 1 '15 at 16:36













I can't use var_dump because it's code for api and it return only values defined in wsdl.xml file. But I check category by pass it to one of this value. Category model is OK, and it seting to layer correct, and I can get it back by $layer->getCurrentCategory();P

– Quickerz
Jan 1 '15 at 16:44






I can't use var_dump because it's code for api and it return only values defined in wsdl.xml file. But I check category by pass it to one of this value. Category model is OK, and it seting to layer correct, and I can get it back by $layer->getCurrentCategory();P

– Quickerz
Jan 1 '15 at 16:44














You can try to add Mage::log($collection->getSelect(), Zend_Log::INFO, 'blah.log', true); in app/code/core/Mage/Catalog/Model/Layer.php -> public function getFilterableAttributes() before return and to run logged SQL query directly in the database or to compare it with the SQL query that is logged when you open the category through the site.

– michael
Jan 2 '15 at 10:22





You can try to add Mage::log($collection->getSelect(), Zend_Log::INFO, 'blah.log', true); in app/code/core/Mage/Catalog/Model/Layer.php -> public function getFilterableAttributes() before return and to run logged SQL query directly in the database or to compare it with the SQL query that is logged when you open the category through the site.

– michael
Jan 2 '15 at 10:22













getFilterableAttributes() return empty array because $setIds = $this->_getSetIds() return empty array. It happen because $this->getProductCollection() return empty collection. Maybe something else needed fo $layer to get product collection from it?

– Quickerz
Jan 5 '15 at 7:24






getFilterableAttributes() return empty array because $setIds = $this->_getSetIds() return empty array. It happen because $this->getProductCollection() return empty collection. Maybe something else needed fo $layer to get product collection from it?

– Quickerz
Jan 5 '15 at 7:24











2 Answers
2






active

oldest

votes


















0














Most probably you didn't set the store id, we need to do so since it's implemented in the api:



protected function _retrieve(){

$id = $this->getRequest()->getParam('id');
$store_id = $this->getRequest()->getParam('store_id');

$category = Mage::getModel("catalog/category")->load($id);
$category->setStoreId($store_id);

if (!($category->getId())) $this->_critical(self::RESOURCE_NOT_FOUND);

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





share|improve this answer






























    0














    following code is used to get filterable attributes and their options



    $categoryId = '5'; // replace with your category id
    $category = Mage::getModel("catalog/category")->load($categoryId);
    $layer = Mage::getModel("catalog/layer");
    $layer->setCurrentCategory($category);

    $setIds = Mage::getModel('eav/entity_attribute_set')
    ->load($attrSetName, 'attribute_set_name')
    ->getAttributeSetId();

    $attributes = Mage::getResourceModel('catalog/product_attribute_collection');
    $attributes->setItemObjectClass('catalog/resource_eav_attribute')
    ->setAttributeSetFilter($setIds)
    ->addStoreLabel(Mage::app()->getStore()->getId())
    ->setOrder('position', 'ASC');


    $attributes->addFieldToFilter('additional_table.is_filterable', array('gt' => 0));
    $attributes->load();

    foreach ($attributes as $attribute)
    $filter_attr = array();
    $filter_attr['title'] = $attribute->getFrontendLabel();
    $filter_attr['code'] = $attribute->getAttributeCode();

    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();
    $i=0;

    foreach($result->getItems() as $option)
    $attr_option = array();
    if($attribute->getAttributeCode() == 'price')
    $attr_option['label'] = str_replace(array('<span class="price">','</span>'),'',$option->getLabel());
    else
    $attr_option['label'] = $option->getLabel();


    $attr_option['value'] = $option->getValue();
    $attr_option['count'] = $option->getCount();
    $i++;
    $filter_attr['options'][] = $attr_option;


    if($i!=0)
    $filter_attributes[] = $filter_attr;







    share|improve this answer























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "479"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f49891%2fget-empty-result-when-trying-to-get-filterable-attribute-for-particular-category%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Most probably you didn't set the store id, we need to do so since it's implemented in the api:



      protected function _retrieve(){

      $id = $this->getRequest()->getParam('id');
      $store_id = $this->getRequest()->getParam('store_id');

      $category = Mage::getModel("catalog/category")->load($id);
      $category->setStoreId($store_id);

      if (!($category->getId())) $this->_critical(self::RESOURCE_NOT_FOUND);

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





      share|improve this answer



























        0














        Most probably you didn't set the store id, we need to do so since it's implemented in the api:



        protected function _retrieve(){

        $id = $this->getRequest()->getParam('id');
        $store_id = $this->getRequest()->getParam('store_id');

        $category = Mage::getModel("catalog/category")->load($id);
        $category->setStoreId($store_id);

        if (!($category->getId())) $this->_critical(self::RESOURCE_NOT_FOUND);

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





        share|improve this answer

























          0












          0








          0







          Most probably you didn't set the store id, we need to do so since it's implemented in the api:



          protected function _retrieve(){

          $id = $this->getRequest()->getParam('id');
          $store_id = $this->getRequest()->getParam('store_id');

          $category = Mage::getModel("catalog/category")->load($id);
          $category->setStoreId($store_id);

          if (!($category->getId())) $this->_critical(self::RESOURCE_NOT_FOUND);

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





          share|improve this answer













          Most probably you didn't set the store id, we need to do so since it's implemented in the api:



          protected function _retrieve(){

          $id = $this->getRequest()->getParam('id');
          $store_id = $this->getRequest()->getParam('store_id');

          $category = Mage::getModel("catalog/category")->load($id);
          $category->setStoreId($store_id);

          if (!($category->getId())) $this->_critical(self::RESOURCE_NOT_FOUND);

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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 19 '16 at 12:46









          Yehia A.SalamYehia A.Salam

          105420




          105420























              0














              following code is used to get filterable attributes and their options



              $categoryId = '5'; // replace with your category id
              $category = Mage::getModel("catalog/category")->load($categoryId);
              $layer = Mage::getModel("catalog/layer");
              $layer->setCurrentCategory($category);

              $setIds = Mage::getModel('eav/entity_attribute_set')
              ->load($attrSetName, 'attribute_set_name')
              ->getAttributeSetId();

              $attributes = Mage::getResourceModel('catalog/product_attribute_collection');
              $attributes->setItemObjectClass('catalog/resource_eav_attribute')
              ->setAttributeSetFilter($setIds)
              ->addStoreLabel(Mage::app()->getStore()->getId())
              ->setOrder('position', 'ASC');


              $attributes->addFieldToFilter('additional_table.is_filterable', array('gt' => 0));
              $attributes->load();

              foreach ($attributes as $attribute)
              $filter_attr = array();
              $filter_attr['title'] = $attribute->getFrontendLabel();
              $filter_attr['code'] = $attribute->getAttributeCode();

              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();
              $i=0;

              foreach($result->getItems() as $option)
              $attr_option = array();
              if($attribute->getAttributeCode() == 'price')
              $attr_option['label'] = str_replace(array('<span class="price">','</span>'),'',$option->getLabel());
              else
              $attr_option['label'] = $option->getLabel();


              $attr_option['value'] = $option->getValue();
              $attr_option['count'] = $option->getCount();
              $i++;
              $filter_attr['options'][] = $attr_option;


              if($i!=0)
              $filter_attributes[] = $filter_attr;







              share|improve this answer



























                0














                following code is used to get filterable attributes and their options



                $categoryId = '5'; // replace with your category id
                $category = Mage::getModel("catalog/category")->load($categoryId);
                $layer = Mage::getModel("catalog/layer");
                $layer->setCurrentCategory($category);

                $setIds = Mage::getModel('eav/entity_attribute_set')
                ->load($attrSetName, 'attribute_set_name')
                ->getAttributeSetId();

                $attributes = Mage::getResourceModel('catalog/product_attribute_collection');
                $attributes->setItemObjectClass('catalog/resource_eav_attribute')
                ->setAttributeSetFilter($setIds)
                ->addStoreLabel(Mage::app()->getStore()->getId())
                ->setOrder('position', 'ASC');


                $attributes->addFieldToFilter('additional_table.is_filterable', array('gt' => 0));
                $attributes->load();

                foreach ($attributes as $attribute)
                $filter_attr = array();
                $filter_attr['title'] = $attribute->getFrontendLabel();
                $filter_attr['code'] = $attribute->getAttributeCode();

                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();
                $i=0;

                foreach($result->getItems() as $option)
                $attr_option = array();
                if($attribute->getAttributeCode() == 'price')
                $attr_option['label'] = str_replace(array('<span class="price">','</span>'),'',$option->getLabel());
                else
                $attr_option['label'] = $option->getLabel();


                $attr_option['value'] = $option->getValue();
                $attr_option['count'] = $option->getCount();
                $i++;
                $filter_attr['options'][] = $attr_option;


                if($i!=0)
                $filter_attributes[] = $filter_attr;







                share|improve this answer

























                  0












                  0








                  0







                  following code is used to get filterable attributes and their options



                  $categoryId = '5'; // replace with your category id
                  $category = Mage::getModel("catalog/category")->load($categoryId);
                  $layer = Mage::getModel("catalog/layer");
                  $layer->setCurrentCategory($category);

                  $setIds = Mage::getModel('eav/entity_attribute_set')
                  ->load($attrSetName, 'attribute_set_name')
                  ->getAttributeSetId();

                  $attributes = Mage::getResourceModel('catalog/product_attribute_collection');
                  $attributes->setItemObjectClass('catalog/resource_eav_attribute')
                  ->setAttributeSetFilter($setIds)
                  ->addStoreLabel(Mage::app()->getStore()->getId())
                  ->setOrder('position', 'ASC');


                  $attributes->addFieldToFilter('additional_table.is_filterable', array('gt' => 0));
                  $attributes->load();

                  foreach ($attributes as $attribute)
                  $filter_attr = array();
                  $filter_attr['title'] = $attribute->getFrontendLabel();
                  $filter_attr['code'] = $attribute->getAttributeCode();

                  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();
                  $i=0;

                  foreach($result->getItems() as $option)
                  $attr_option = array();
                  if($attribute->getAttributeCode() == 'price')
                  $attr_option['label'] = str_replace(array('<span class="price">','</span>'),'',$option->getLabel());
                  else
                  $attr_option['label'] = $option->getLabel();


                  $attr_option['value'] = $option->getValue();
                  $attr_option['count'] = $option->getCount();
                  $i++;
                  $filter_attr['options'][] = $attr_option;


                  if($i!=0)
                  $filter_attributes[] = $filter_attr;







                  share|improve this answer













                  following code is used to get filterable attributes and their options



                  $categoryId = '5'; // replace with your category id
                  $category = Mage::getModel("catalog/category")->load($categoryId);
                  $layer = Mage::getModel("catalog/layer");
                  $layer->setCurrentCategory($category);

                  $setIds = Mage::getModel('eav/entity_attribute_set')
                  ->load($attrSetName, 'attribute_set_name')
                  ->getAttributeSetId();

                  $attributes = Mage::getResourceModel('catalog/product_attribute_collection');
                  $attributes->setItemObjectClass('catalog/resource_eav_attribute')
                  ->setAttributeSetFilter($setIds)
                  ->addStoreLabel(Mage::app()->getStore()->getId())
                  ->setOrder('position', 'ASC');


                  $attributes->addFieldToFilter('additional_table.is_filterable', array('gt' => 0));
                  $attributes->load();

                  foreach ($attributes as $attribute)
                  $filter_attr = array();
                  $filter_attr['title'] = $attribute->getFrontendLabel();
                  $filter_attr['code'] = $attribute->getAttributeCode();

                  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();
                  $i=0;

                  foreach($result->getItems() as $option)
                  $attr_option = array();
                  if($attribute->getAttributeCode() == 'price')
                  $attr_option['label'] = str_replace(array('<span class="price">','</span>'),'',$option->getLabel());
                  else
                  $attr_option['label'] = $option->getLabel();


                  $attr_option['value'] = $option->getValue();
                  $attr_option['count'] = $option->getCount();
                  $i++;
                  $filter_attr['options'][] = $attr_option;


                  if($i!=0)
                  $filter_attributes[] = $filter_attr;








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 19 '16 at 12:56









                  Pradeep SankuPradeep Sanku

                  7,93113157




                  7,93113157



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Magento Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f49891%2fget-empty-result-when-trying-to-get-filterable-attribute-for-particular-category%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                      Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                      Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form