Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I can manage to get the order shipping address in MY_MODULE_calculate_shipping (price depends on shipping country) when the buyer is logged in.
When he is anonymous, I can't find information about the shipping address in the $order object ...
Could someone tell me what I'm missing ?
Comments
Comment #1
guy_schneerson CreditAttribution: guy_schneerson commentedI had the same problem, I think the issue is that the address gets saved after the calculate shipping is called, if you are logged in you will get an address if it is already saved, so if you changed the country from UK to France the calculate_shipping will see UK.
The way I got around this is by capturing the address information using the hook_form_alter, but its not the most elegant of solutions.
Comment #2
googletorp CreditAttribution: googletorp commentedI have create a solution for this, by adding the $form and $form_state values to the calculate function. This will hold all values submitted along with the shipping method. This along with the order object itself should provide the info needed.
Please test and let me know if this doesn't work for you.
Commit: 50a8838
Comment #4
1kenthomas CreditAttribution: 1kenthomas commentedSorry, per http://drupal.org/node/1262678; I looked at those and with the shipping pane displaying below the billing pane, $form etc. did not have address data available.
Comment #5
googletorp CreditAttribution: googletorp commented#4 You have the $form_state ($pane_values) available, so you can access any value that has been submitted.
It's not necessarily easy or pretty to do so, but it should make you able to get the job done.
I try to give as much info to shipping methods as possible but am limited by the FAPI and the Drupal Commerce pane system. If you feel something is wrong, this is where you should raise the issue. As I see it commerce shipping cannot do anything more in this area.