1

I try to create module for custom filter.phtml, but rewriting doesn't work and it show default template for layered navigation options. I tried many ways but without success and now I have no idea why this thing doesn't work. Here is my code:

config.xml

<My_Module>

  <version>0.1.0</version>

</My_Module>

<blocks>

    <my_module>

      <class>My_Module_Block</class>

    </my_module>

    <catalog>

      <rewrite>
        <layer_filter_abstract>My_Module_Block_Layer_Filter_Abstract</layer_filter_abstract>

      </rewrite>

    </catalog>

</blocks>

Block/Catalog/Layer/Filter/Abstract.php (I also had tried without "Catalog")

class My_Module_Block_Layer_Filter_Abstract extends Mage_Catalog_Block_Layer_Filter_Abstract {

public function __construct()
{
    parent::__construct();
    $this->setTemplate('module/catalog/layer/filter.phtml');
}

}

Maby somebody can help me?

1

You cannot rewrite an abstract class in Magento. You can only rewrite classes that you instantiate directly and since abstract class is never instantiated, it can never be rewritten.

The only way to override this specific class would be to copy it over to local code pool, following the same path structure, but I highly discourage this approach.

Much better option, in your case, would be to rewrite Mage_Catalog_Block_Layer_View class and modify it's _prepareLayout method. I've added comments in the code below.

protected function _prepareLayout()
{
    $stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
        ->setLayer($this->getLayer());

    $categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
        ->setLayer($this->getLayer())
        ->init();

    $this->setChild('layer_state', $stateBlock);
    $this->setChild('category_filter', $categoryBlock);

    $filterableAttributes = $this->_getFilterableAttributes();
    foreach ($filterableAttributes as $attribute) {
        if ($attribute->getAttributeCode() == 'price') {
            $filterBlockName = $this->_priceFilterBlockName;
        } elseif ($attribute->getBackendType() == 'decimal') {
            $filterBlockName = $this->_decimalFilterBlockName;
        } else {
            $filterBlockName = $this->_attributeFilterBlockName;
        }

        // This is where one of the Mage_Catalog_Block_Layer_Filter_* classes
        // are instantiated. They all extend Mage_Catalog_Block_Layer_Filter_Abstract
        // which means that you can call setTemplate here and redefine one that is
        // set in abstract class. You can also set different templates based block type.

        $this->setChild($attribute->getAttributeCode() . '_filter',
            $this->getLayout()->createBlock($filterBlockName)
                // Set your template here
                ->setTemplate('module/catalog/layer/filter.phtml')
                ->setLayer($this->getLayer())
                ->setAttributeModel($attribute)
                ->init());
    }

    $this->getLayer()->apply();

    return $this;
}
| improve this answer | |

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.