简体   繁体   中英

Magento: How to add the widget button to the WYSIWYG Products Editor

I want to allow adding the Catalog Product Link widget in the description field of a product (so I can easily link to other products in the description). I've already extended Mage_Catalog_Model_Product by creating a file like:

class mymodule_Catalog_Model_Product extends Mage_Catalog_Model_Product
{

    /**
      * Add getDescription function that interprets widget or static blocks
      * within product descriptions
      */
    public function getDescription() {
        $processor = Mage::getModel('widget/template_filter');
        $html = $processor->filter($this->getData('description'));
        return $html;
    }

}

Now it works fine if I type something like

{{widget type="catalog/product_widget_link" anchor_text="my text" template="catalog/product/widget/link/link_inline.phtml" id_path="product/1234"}}

into the description field -- it creates a link to the product Id 1234.

But I want to add the actual Catalog Product Link widget button in the WYSIWYG editor for editing a product. The button is already in the CMS editor, but I am missing what I need to modify in order to add this widget to the Admin interface for editing a product. Can someone help me out?

For anybody stumbling across this later on like myself, you can use the cms_wysiwyg_config_prepare event to set this to true.

EG: in config.xml

<events>
            <cms_wysiwyg_config_prepare>
                <observers>
                    <webtise_widgets>
                        <class>webtise_widgets/observer</class>
                        <method>cmsWysiwygConfigPrepare</method>
                    </webtise_widgets>
                </observers>
            </cms_wysiwyg_config_prepare>
        </events>

In your observer

<?php class Webtise_Widgets_Model_Observer{

    public function cmsWysiwygConfigPrepare(Varien_Event_Observer $observer){
        $observer->getEvent()->getConfig()->setAddWidgets(true);
    }
}

I was able to do this by overriding the core file

app/code/local/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg/Content.php

and setting

$config['add_widgets']           = true;

Now the widget button shows up in all WYSIWIG editors in the admin interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM