From the beginning I want to apologize for my poor English! I have a task to make the proper storage of information in the customer session in Magento on the page checkout. When i try to save billing address of a guest user i had rewrite billing model and all ok. But when user is logged in and has several address in his address book i saw interesting thing…. I had rewrite billing model more to save a customer address id and save selected address but when user select an option in select "New address", form data save in quote and when i try to get it with getQuote()->getBillingAddress() i took the default user address (when user not logged in all work good) How i can do this task ?? I need help because this important task for me … A lot of thx !!!
Php – Magento save billing address in Quote
magentomagento-1.5PHP
Related Solutions
Whatever you do, make sure not to trust data sent from the client. $_SERVER['REMOTE_ADDR']
contains the real IP address of the connecting party. That is the most reliable value you can find.
However, they can be behind a proxy server in which case the proxy may have set the $_SERVER['HTTP_X_FORWARDED_FOR']
, but this value is easily spoofed. For example, it can be set by someone without a proxy, or the IP can be an internal IP from the LAN behind the proxy.
This means that if you are going to save the $_SERVER['HTTP_X_FORWARDED_FOR']
, make sure you also save the $_SERVER['REMOTE_ADDR']
value. E.g. by saving both values in different fields in your database.
If you are going to save the IP to a database as a string, make sure you have space for at least 45 characters. IPv6 is here to stay and those addresses are larger than the older IPv4 addresses.
(Note that IPv6 usually uses 39 characters at most but there is also a special IPv6 notation for IPv4 addresses which in its full form can be up to 45 characters. So if you know what you are doing you can use 39 characters, but if you just want to set and forget it, use 45).
After looking in the Magento's code and reading the wiki, I was able to complete it, 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 located 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 help someone else
Best Answer
If I am parsing your question correctly, are you saying that
getQuote()->getBillingAddress()
is getting the customer's default billing address instead of the new address the customer has entered in the order?I have this problem in Magento 1.4.0.1 as well, I worked around it by getting all the addresses from the customer and comparing every attribute with the address specified in the order to find out the real entity ID of the address.
I copied this from my code with some parts of custom business logic removed, so consider it untested, but you get the idea:
(The code is only tested on Magento 1.4.0.1 and might not apply to Magento 1.5)