I want to add a new field "custom_house_no" for the shipping address during the onepage checkout process.
I have added the below code in my custom extension mysql file "mysql4-install-0.1.0.php"
// Customer Address
$entityTypeId = $installer->getEntityTypeId('customer_address');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute('customer_address', 'custom_house_no', array(
'label' => 'Custom House No',
'input' => 'text', // Input field type textbox
'type' => 'varchar', // Store varchar data type
'frontend' => '', //frontend model
'backend' => '', //backend model
'visible' => 1, //true
'required' => 0, //false
'user_defined' => 1,
'default' => '', //default value
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'unique' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
// 'class' => '',
// 'source' => 'catalog/category_attribute_source_page',
));
$installer->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'custom_house_no',
'150' //last Magento'开发者_运维问答s attribute position in General tab is 140
);
$attribute = Mage::getSingleton('eav/config')->getAttribute('customer_address', 'custom_house_no');
$attribute->setData('used_in_forms', array('customer_register_address', 'customer_address_edit', 'adminhtml_customer_address')); // Setting the relation between the attribute and forms in which this attribute will be used
$attribute->save();`
I have also made a class in folder MY/CustomExtension/Model/Entity/Setup.php
class MY_CustomExtension_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup {
}
I have also added the class name in the extension config file.
Link to config code : Config File Content
And in the shipping template file i have added the textbox with the name "custom_house_no".
The attribute has been added successfully and he relationship with the forms, but all the data is getting save in the database except the "custom_house_no" field.
Most likely you need to play with fieldsets. Take a look at those defined in config.xml of core Mage/Checkout module and extend them in your module config
精彩评论