如何通过安装脚本设置属性的默认值?
-
16-10-2019 - |
题
我已经使用自定义模块的安装脚本创建了一个属性。一个属性是一个下拉列表,只有两个选项为“是”,“否”。另一个属性是文本字段。我需要通过此脚本设置默认值。我捆绑了以下内容。但没有工作。
$th = new Mage_Catalog_Model_Resource_Setup();
$th->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'credit', array(
'group' => 'Prices',
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Credit rewards',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => 'kkkkkkkk', // this is default value. but is's not setting
'searchable' => false,
'filterable' => true,
'comparable' => false,
'visible_on_front' => true,
'visible_in_advanced_search' => true,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => 'simple',
) );
任何建议将不胜感激。先谢谢了。
解决方案
/**
* @var $th Mage_Eav_Model_Entity_Setup
*/
$th =new Mage_Eav_Model_Entity_Setup('core_setup');
$th->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'credit', array(
'group' => 'Prices',
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Credit rewards',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => 'kkkkkkkk', // this is default value.
'searchable' => false,
'filterable' => true,
'comparable' => false,
'visible_on_front' => true,
'visible_in_advanced_search' => true,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => 'simple',
));
其他提示
/**
* @var $th Mage_Eav_Model_Entity_Setup
*/
$th =new Mage_Eav_Model_Entity_Setup('core_setup');
$th->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'credit', array(
'group' => 'Prices',
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Credit rewards',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => 'kkkkkkkk', // this is default value.
'searchable' => false,
'filterable' => true,
'comparable' => false,
'visible_on_front' => true,
'visible_in_advanced_search' => true,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => 'simple',
));