Magento – Add Magento Widget parameters to the Add Widget Instance editor

magentowidget

This question appears to have been asked multiple time, but not answered.

I've created a widget that adds attribute values to a configurable product. Just to be clear, if a configurable product is made up of multiple simple products (associated products) based on attributes size and color, then I want to display the 'available' sizes and colors for this configurable product to the customer. And, I want to do it programmatically rather than just put a list of sizes and colors in the description because not all sizes or colors might be available at the moment. So I've created this widget.

Now, I wanted to make a more generic version of this widget that could use any associated product's attribute. But, to do this the admin setting up the widget would need to select the attribute from a list of available attributes. This actually can work when adding a widget to a CMS page because the parameters defined in the widget.xml file allow that.

The problem is that I'm not adding the widget to a CMS page. I'm adding it to product pages. So I need to use the Widget Instance feature at CMS -> Widgets -> Add New Widget Instance editor. However, this editor has tabs for Frontend Properties and Widget Options. And the parameters from the widget.xml file are not shown in the Widget Options tab of this editor.

So, is there a way to add parameters to the Widget Options tab of the Add a Widget Instance editor from the widget.xml file (e.g. something like:

<widgets>
  <Widget Options>
    <parameters>
      <my_widget_instance_parameter> ... </my_widget_instance_parameter>
    </parameters>
  </Widget Options>
</widget>

Or is this something that requires enhancing the actual widget instance editor?

Thanks.

Best Answer

Go to \app\code\core\Mage\Cms\etc\widget.xml and look at CMS Page Link widget options:

<cms_page_link type="cms/widget_page_link" translate="name description" module="cms">
    <name>CMS Page Link</name>
    <description>Link to a CMS Page</description>
    <is_email_compatible>1</is_email_compatible>
    <parameters>
        <page_id type="complex" translate="label">
            <visible>1</visible>
            <required>1</required>
            <label>CMS Page</label>
            <type>label</type>
            <helper_block>
                <type>adminhtml/cms_page_widget_chooser</type>
                <data>
                    <button translate="open">
                        <open>Select Page...</open>
                    </button>
                </data>
            </helper_block>
            <sort_order>10</sort_order>
        </page_id>
        <anchor_text translate="label description">
            <visible>1</visible>
            <label>Anchor Custom Text</label>
            <description>If empty, the Page Title will be used</description>
            <type>text</type>
        </anchor_text>
        <title translate="label">
            <visible>1</visible>
            <label>Anchor Custom Title</label>
            <type>text</type>
        </title>
        <template translate="label">
            <label>Template</label>
            <visible>1</visible>
            <type>select</type>
            <value>cms/widget/link/link_block.phtml</value>
            <values>
                <default translate="label">
                    <value>cms/widget/link/link_block.phtml</value>
                    <label>CMS Page Link Block Template</label>
                </default>
                <link_inline translate="label">
                    <value>cms/widget/link/link_inline.phtml</value>
                    <label>CMS Page Link Inline Template</label>
                </link_inline>
            </values>
        </template>
    </parameters>
</cms_page_link>

As you can see, parameters can have simple type (text, select) and more complex type with helper block:

            <helper_block>
                <type>adminhtml/cms_page_widget_chooser</type>
                <data>
                    <button translate="open">
                        <open>Select Page...</open>
                    </button>
                </data>
            </helper_block>

Type here is helper block class name in magento notation.

Related Topic