Magento — добавление нового поля для адреса доставки во время оформления заказа на одной странице

Я хочу добавить новое поле «custom_house_no» для адреса доставки в процессе оформления заказа на одной странице.

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();`

Я также создал класс в папке 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».

Я не знаю, что не так с моим кодом.


person MagDev    schedule 09.08.2011    source источник


Ответы (1)


Скорее всего, вам нужно поиграть с наборами полей. Взгляните на те, что определены в config.xml основного модуля Mage/Checkout, и расширьте их в конфигурации вашего модуля.

person Zifius    schedule 10.08.2011