Magento: programmatically change widget configuration

I want to change and save the widget configuration from the widget code. I am looking for something like this:

class My_Module_Block_Widget
    extends Mage_Catalog_Block_Product_List
    implements Mage_Widget_Block_Interface
{
    // ...
    protected function _beforeToHtml()
    {
        // ...
        if(/* data needs to be changed */)
        {
            // assuming "widget_config_data" to be one of the widget's
            // parameters configured in the etc/widget.xml file of my module
            $this->setData("widget_config_data", "New Data");
            $this->save();
        }
        // ...
    }
    // ...
}

Since widgets are not models, they do not have a save () method. So how can I save the changed data of my widget?

+5
source share
1 answer

It will be difficult, and probably more important, that one question is about stack overflow. Here is some background for you to get started. The class / object you are dealing with above is a block class. Blocks are used for rendering HTML. They, as you have already noted, are stateless.

The block gets its data from the widget instance model object.

Mage::getModel('widget/widget_instance');
Mage_Widget_Model_Widget_Instance

The state of these objects (the data you are trying to change) is in the table widget_instance

, . , ( , ). , ,

<reference name="content">
    <block type="cms/widget_page_link" name="48fc761f38fa9838fcc3a3b498c47f72" template="cms/widget/link/link_block.phtml">
        <action method="setData">
            <name>anchor_text</name>
            <value>asdfasdfsad</value>
        </action>
        <action method="setData">
            <name>title</name>
            <value>asdfasdfasdfasd</value>
        </action>
        <action method="setData">
            <name>page_id</name>
            <value>2</value>
        </action>
    </block>
</reference>

, , .

paramater, . widget_paramater, . , SQL . //, foreach , . , . , , ( ), .

( ) - , XML- . , . , .

!

+10

All Articles