Magento : Enable Widget/Block Codes in Catalog Product

In a recent task, I created a widget, which was about to insert a email opt-in form in the description area.

After creating the widget, I realized the widget worked fine, when placed in WYSIWYG editor in CMS module, but didn’t work if placed in the description field for Product.

After a bit of digging into the template parsing core classes, it was realized  that Magento didn’t support rendering block/widget directives in Catalog section.

So we decided to extend the parsing class, to enable the required feature.

Please find below steps on extending the core class ‘Mage_Catalog_Model_Template_Filter’ and add the required methods to enable the rendering for widget and block directives

1. Create a new module and place it under ‘local’ folder. I named it ‘Maniacs_Directive’

2. Add rewrite in the config file, for the new created module, in order to extend the core file

<catalog>
<rewrite>
<template_filter>Maniacs_Directive_Model_Catalog_Template_Filter</template_filter>
</rewrite>
</catalog>

3. Inside the new class ‘Maniacs_Directive_Model_Catalog_Template_Filter’, add the two methods named as follows: ‘blockDirective’ & ‘widgetDirective’

4. Contents for method ‘blockDirective’, are as follows:

public function blockDirective($construction) {
$model=Mage::getModel('core/email_template_filter');
return $model->blockDirective($construction);
}

5. Contents for method ‘widgetDirective’, are as follows:

public function widgetDirective($construction) {
$construction[2] .= sprintf(' store_id ="%s"', $this->getStoreId());
$model=Mage::getModel('widget/template_filter');
return $model->widgetDirective($construction);
}

This should enable, the rendering, and all the admin has to do is to add directive codes into the WYSIWYG editor.

 

Advertisements

4 thoughts on “Magento : Enable Widget/Block Codes in Catalog Product

  1. Hi,
    I followed your advice but it doesn’t work. i still cannot add directive codes into the WYSIWYG editor of product description.
    Maybe i am doing something wrong. Can you PLEASE create this module and put it in a zip file here.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s