How to set default value to "Yes" in generated select element? I created installation script and attribute is created perfectly. But on create/edit page of product I get No selected attribute for option.
<select class=" select" name="product[abroad_shipping]" id="abroad_shipping">
<option value="1">Yes</option>
<option selected="selected" value="0">No</option>
</select>
<?php
/* @var $this Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
/* @var $setup Mage_Eav_Model_Entity_Setup */
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('catalog_product');
$setup->removeAttribute($entityTypeId, 'abroad_shipping');
$attributeData = array(
'type' => 'int',
'input' => 'select',
'label' => 'Possible abroad shipping',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'required' => false,
'user_defined' => true,
'default_value' => '1',
'default' => array('1'),
// 'default' => '1',
// 'option' => array(
// 'values' =>
// array(
// 0 => 'Yes',
// 1 => 'No'
// )
// ),
);
$setId = $setup->getAttributeSetId($entityTypeId, 'my_custom_set');
$groupId = $setup->getAttributeGroupId($entityTypeId, $setId, null);
$setup->addAttribute($entityTypeId, 'abroad_shipping', $attributeData);
$setup->addAttributeToGroup($entityTypeId, $setId, $groupId, 'abroad_shipping', 90);
$installer->endSetup();
I tried default, default value, integer default, string default, array. Nothing worked.
Best Answer
default
is the correct method for setting default values for the drop down, For example, My custom options are like,And your installer script should be like this,
Here the
default
having values is2
. That meansMyoption-2
is the default option. You may be entered wrong value. check the value of that option that you need to set as adefault
.