Magento - 在一个页面结帐过程中为送货地址添加新字段

时间:2011-08-09 07:05:03

标签: magento checkout shipping street-address

我想在单页结帐过程中为送货地址添加新字段“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();`

$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 {
    }
    

在发货模板文件中,我添加了名为“custom_house_no”的文本框。

该属性已成功添加,并且与表单有关系,但除“custom_house_no”字段外,所有数据都将保存在数据库中。

我不知道我的代码有什么问题。

1 个答案:

答案 0 :(得分:0)

您很可能需要使用字段集。看看核心Mage / Checkout模块的config.xml中定义的那些,并在模块配置

中扩展它们