Magento - 在单页结帐过程中添加送货地址的新字段
我想在单页结帐过程中为送货地址添加一个新字段“custom_house_no”。
我在自定义扩展 mysql 文件“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();`
<代码>
我还在文件夹 MY/CustomExtension/Model/Entity/Setup.php 中创建了一个类
class MY_CustomExtension_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup {
}
我还在扩展配置文件中添加了类名。
Link to config code : Config File Content
在运输模板文件中,我添加了名为“custom_house_no”的文本框。
该属性已成功添加,并且与表单建立了关系,但除“custom_house_no”字段外,所有数据都保存在数据库中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您很可能需要使用fieldsets。查看核心 Mage/Checkout 模块的 config.xml 中定义的内容,并在模块配置中扩展它们
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