Comment définir la valeur par défaut pour un attribut par script d'installation?
-
16-10-2019 - |
Question
J'ai créé un attributs à l'aide d'un script d'installation pour un module personnalisé. Un attribut est un menu déroulant qui n'a que deux options que « oui », « non ». L'autre attribut est un champ de texte. Dois-je définir des valeurs par défaut par ce script. Je ligoté ce qui suit. Mais n'a pas marché.
$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',
) );
Toute suggestion sera appréciée. Merci d'avance.
La solution
/**
* @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',
));
Autres conseils
/**
* @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',
));
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange