3

I need to show the layer navigation filter values in above the search page heading.

enter image description here

I have tried below code in the app\design\frontend\rwd\default\template\catalogsearch\result.phtml file.

$layout         = Mage::getSingleton('core/layout');
$block_header   = $layout->createBlock('catalog/layer_state')->setTemplate('catalog/layer/state_1.phtml');
$block_links    = $layout->createBlock('core/text_list','catalog.leftnav.state.renderers');
$block_header->setChild('state_renderers',$block_links);
echo $block_header->toHtml();

But I am getting empty value.

Please assist me.

  • are you using third party extension or creating new one? – Qaisar Satti Jan 6 '16 at 5:40
  • I did not used any third party extension, I have created the custom attributes in backend. – VijayS91 Jan 6 '16 at 5:48
  • i think you can get value by Mage::app()->getRequest()->getParam('your params'); – Qaisar Satti Jan 6 '16 at 5:50
  • Yes its possible, But did not get correct format as per filter showing in left side navigation. – VijayS91 Jan 6 '16 at 6:08
2

you can get active filter with below code. tested code..

for category page

 <?php 
$_filters = Mage::getSingleton('catalog/layer')->getState()->getFilters();

foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter->getRemoveUrl() ?>” title=”<?php echo $this->__('Remove This Item') ?>”><?php echo $this->__('Remove This Item') ?></a>
<?php endforeach; ?>

for search page

    <?php 
 $_filters = Mage::getSingleton('catalogsearch/layer')->getState()->getFilters();

foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter->getRemoveUrl() ?>” title=”<?php echo $this->__('Remove This Item') ?>”><?php echo $this->__('Remove This Item') ?></a>
<?php endforeach; ?>

or you want to show only the current filter state use this code

for category page

<?php echo $this->getLayout()->createBlock('catalog/layer_state')->setTemplate('catalog/layer/state.phtml')->toHtml(); ?>

for search result

<?php echo Mage::app()->getLayout()->createBlock('catalogsearch/layer')->setTemplate('catal‌​og/layer/state.phtml')->toHtml(); ?>
  • I have printed the array "print_r($_filters);" I am getting empty array value.I have filtered two options (rating ,price). – VijayS91 Jan 6 '16 at 6:44
  • try it again there was error in code.. – Qaisar Satti Jan 6 '16 at 6:48
  • I am did not get error, I have print the array I am getting " Array () ". – VijayS91 Jan 6 '16 at 6:51
  • try this $appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters(); – Qaisar Satti Jan 6 '16 at 6:54
  • my bad luck, I am getting empty array. – VijayS91 Jan 6 '16 at 7:00

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.