Magento: save custom address attribute in checkout

青春壹個敷衍的年華 提交于 2019-12-30 05:06:47

问题


this is what i did in my website: Admin->Customers->Attributes->Manage Customer Address Attributes and add a new attribute , the user can see it in his/her profile, under My Addresses option, the new attribute can be edited and is saved when creating a new address, i also can see it in the backend, and edited, untill here everything is ok, my problem is in the checkout, i already have the field in the billing and shipping forms and i want the new attribute to be saved when the user click "Place Order" button, but, checkout seems it doesn't know nothing about the new attribute, the attribute is not saved and if i save one value from the user profile checkout doesn't load it in the field.

what can i do here??

thanks


回答1:


After looking in the magento's code and reading the wiki, i was able to completed, my new attribute was saved in the address edit form in the profile, but was not saved when i enter it in the checkout form, that was because i need to override some magento core files, the first step was adding the new attribute to app\code\core\Mage\Customer\etc\config.xml, i copied to app\code\core\Mycompany\Customer\etc\config.xml, as my new attribute code is rfc, i locate the <fieldsets> entry and

<customer_dataflow>
    ....
    <rfc><billing>1</billing><shipping>1</shipping></rfc>
</customer_dataflow>

now i need to add the new attribute to the app\code\core\Mage\Customer\Model\Entity\Setup.php i did the same to override, copied to my local namespace, and in the function getDefaultEntities() i locate the

'customer_address'=>array(
    ....
            'rfc' => array(
            'label'         => 'RFC',
            'required'      => false,
            'sort_order'    => 135,
    ),
)  

now, i need to do also the same in app\code\core\Mage\Sales\etc\config.xml, but now should look like this

<sales_copy_order_billing_address>
    .....
    <rfc><to_order>*</to_order></rfc>
</sales_copy_order_billing_address>

<sales_copy_order_shipping_address>
    ......
    <rfc><to_order>*</to_order></rfc>
</sales_copy_order_shipping_address>

<sales_convert_quote_address>
    ........
    <rfc><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></rfc>
</sales_convert_quote_address>

<sales_convert_order_address>
    .........
    <rfc><to_quote_address>*</to_quote_address></rfc>
</sales_convert_order_address>

<customer_address>
    .......
    <rfc><to_quote_address>*</to_quote_address></rfc>
</customer_address>

Hope it can helpe someone else



来源:https://stackoverflow.com/questions/5609987/magento-save-custom-address-attribute-in-checkout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!