¿Cómo establecer el valor predeterminado para un atributo a través del script de instalación?
-
16-10-2019 - |
Pregunta
He creado un atributos utilizando un script de instalación para un módulo personalizado. Un atributo es un desplegable que solo tiene dos opciones como 'sí', 'no'. El otro atributo es un campo de texto. Necesito establecer valores predeterminados a través de este script. Até lo siguiente. Pero no funcionó.
$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',
) );
Cualquier sugerencia será apreciada. Gracias de antemano.
Solución
/**
* @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',
));
Otros consejos
/**
* @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',
));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange