Fixed it myself by looking at the addAttributeOption()
method inside Mage_Eav_Model_Entity_Setup
:
Result:
$installer->addAttribute('catalog_product', 'tariffplan_sms_slider', array(
'attribute_set' => 'Randomattributeset',
'group' => 'Sample',
'type' => 'varchar',
'default' => 0,
'required' => false,
'visible' => true,
'backend' => 'eav/entity_attribute_backend_array',
'frontend' => '',
'label' => 'Random label',
'note' => '',
'input' => 'multiselect',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
'option' => array (
'values' => array(
'1' => 'Low',
'2' => 'Medium',
'3' => 'High',
'4' => 'Unlimited'
)
),
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => 0,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false
));
For those that don't see it immediately you basically just needed to change the value you give to the "option" key from:
'option' => array ('value' =>
array(
'one' => array("Low"),
'two' => array("Medium"),
'three' => array('High'),
'four' => array('Unlimited')
)
),
TO (see how value changed ito into values):
'option' => array (
'values' => array(
'1' => 'Low',
'2' => 'Medium',
'3' => 'High',
'4' => 'Unlimited'
)
),
Its not pretty, but of course you can create a widget instance programmatically, for example in a setup script:
$widgetParameters = array(
'param1' => 'This is some value from the widget form,
'param2' => 'Some/other/value',
'param2_2' => 'Rly?',
'template' => 'this/is/the/template.phtml'
);
$instance = Mage::getModel('widget/widget_instance')->setData(array(
'type' => 'your_module/your_widget',
'package_theme' => 'default/theme', // has to match the concrete theme containing the template
'title' => 'This is the Widget title',
'store_ids' => '0', // or comma separated list of ids
'widget_parameters' => serialize($widgetParameters),
'page_groups' => array(array(
'page_group' => 'all_pages',
'all_pages' => array(
'page_id' => null,
'group' => 'all_pages',
'layout_handle' => 'default',
'block' => 'left',
'for' => 'all',
'template' => $widgetParameters['template],
)
))
))->save();
This example sets the widget instance to display on every page in the left column.
If you want to specify different pages or target blocks, you need to update the values accordingly. I suggest looking what is set in Mage_Widget_Adminhtml_Widget_InstanceController::saveAction()
and adjust the code above accordingly.
Best Answer
You need to set the attribute group: