php - Magento: Adding a custom EAV attribute that autopopulates with its default value on entity creation -


is there way add custom eav attribute automatically gets set default value upon creation of new entity?

i set eav_attribute.is_required 1 , eav_attribute.default_value 0 (the default value), it's not setting attribute automatically when create new object.

by way, eav entity type shipment. i'm working on installation of 1.3.2.4, before sales data stored in flat tables.

edit

jonathan day asked "how adding attribute?"

in moduledir\sql\module_setup\mysql4-install-0.1.0.php, have following code:

$eav = new mage_eav_model_entity_setup('sales_setup'); $eav->addattribute('shipment', 'fieldname', array('type' => 'int')); 

i have code later versions of magento (after sales entities went eav flat tables):

$w = $this->_conn; $table = $this->gettable('sales_flat_shipment'); $w->addcolumn($table, 'fieldname', 'int'); $w->addkey($table, 'fieldname', 'fieldname', 'index'); 

jonathan day asked "have checked attribute added eav_attribute correct fields?"

yes, has been added eav_attribute. , attribute settable , gettable.

if @ varien_object::getdata() (in /lib/varien/object.php) can see following line:

$default = null; 

...and instance of missing data returns $default. default value set in attribute being ignored.

since undefined 'get' handled getdata() means null default. seems option override sales_model_order_shipment (or whichever entity model is) , provide custom getters.

a simple example be:

function getsample() {     if (!$this->hassample())         return 0;      return $this->getdata('sample'); } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -