Here I come to know about an awesome feature of Magento. When we add any eav attribute to an entity we can give a backend model name. Whenever Entity will be loaded magento initiates Mage_Eav_Model_Entity_Attribute model for each attribut. If it finds any backend model name for a eav attribut, it loads the corresponding model and based on what it is doing it will call different method from that model.
Here I am giving a complete example how you can use this feature. We will add an attribue to address model as “address_verified” , use a backend model to set this value whenever the any address will be save.
Step 1.Create a custom model “Mymodule”
Step 2.Write an sql setup for this module. It will add an “address_verified” attribute to address entity
<?php $installer = $this; $installer->startSetup();
$installer->run("
INSERT INTO {$this->getTable('eav_attribute')} (
`entity_type_id` ,
`attribute_code` ,
`attribute_model` ,
`backend_model` ,
`backend_type` ,
`backend_table` ,
`frontend_model` ,
`frontend_input` ,
`frontend_input_renderer` ,
`frontend_label` ,
`frontend_class` ,
`source_model` ,
`is_global` ,
`is_visible` ,
`is_required` ,
`is_user_defined` ,
`default_value` ,
`is_searchable` ,
`is_filterable` ,
`is_comparable` ,
`is_visible_on_front` ,
`is_html_allowed_on_front` ,
`is_unique` ,
`is_used_for_price_rules` ,
`is_filterable_in_search` ,
`used_in_product_listing` ,
`used_for_sort_by` ,
`is_configurable` ,
`apply_to` ,
`position` ,
`note` ,
`is_visible_in_advanced_search`
)
VALUES (
'2', 'is_validated', NULL , 'customer_entity/address_attribute_backend_validate', 'int', NULL , NULL , 'text', NULL , NULL , NULL , NULL , '1', '1', '0', '0', NULL , '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '', '', '', '0'
);
");
$installer->endSetup();
Step3.Write the back end model in your local code pool
<?php
class Mypackage_Customer_Model_Entity_Address_Attribute_Backend_Validate
extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
public function beforeSave($object)
{
//Write your code to validate address
$object->setIsValidated($satoriStatus);
return $this;
}
}
Step 4. Override the backend model so that it runs from your local pool
</config> <models> <customer_entity> <rewrite> <address_attribute_backend_satori>Mypackage_Customer_Model_Entity_Address_Attribute_Backend_Satori</address_attribute_backend_satori> </rewrite> </customer_entity> </models> <config>

how can this add an attribute called “address_verified” when the word “address_verified” is not anywhere in the code?
what is satori and satoriStatus??
can you please elaborate on how to add an attribute and attribute option from a code in a custom module?
Hello Asad Rahman,
Nice posting there but I want to do something different in the Magento. I want to add a different entity attribute sets for administrator users in magento database. i.e. I am creating different user groups for administrators say seller. Seller are required to register through the front end and then are able to add their own products but are restricted to create categories. i.e. they are given access to backend after registration for adding products and other limited access privilege. And they are allowed to setup their own profile page like http://domainName.com/newSeller. So I want to be able to add different entity sets for administrator users. Any idea will be greatly appreciated. Looking forward for your response. Thanks.
Your requirement is interesting. I haven’t done anything exactly like that. In magento You can create new admin user group and can restrict what they can do . But these users need to be created by super user from admin, not from frontend. I think you can created module to register admin user from front end, automatically accept their registration and then set them to that limited user admin group.
Feel free to ask any question or any help you need.
Hi,
Nice post,
I am trying to add an attribute in products that will be propagated to invoice, order and shipment when created.
I think by using your code I will be able to add attribute, but how to add the same attribute in invoice, order and shipment
Thanks & Regards,
Saurabh