Currently, the Ship From address only comes from the admin settings variables. That makes it impossible to use multiple locations. It also makes it hard to use different countries because currently, it's hard coded for the U.S.
The Ship To address can only come from:
$order_wrapper->{$field_name}->commerce_customer_address->value()
This patch wraps that logic and adds hook_..._alter support for both addresses. Making this change should help address some of the issues brought up by these issues:
#1734920: Shipping from multiple origins The new hook could be used to let you change the ship from address based on the order.
#1313318: Add ship from address outside the US The new hook could let you set a non-U.S. address for the ship from.
#1485894: Modify UPS account forms to allow different services The new hook could be used to let you change the ship from address based on the order.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 2293431-11.patch | 7.15 KB | joshmiller |
| #7 | commerce_ups-2293431-02-nohunk4.patch | 6.85 KB | christiansanders |
| #2 | commerce_ups-2293431-02.patch | 7.52 KB | bendiy |
Comments
Comment #1
bendiy commentedComment #2
bendiy commentedUpdate patch to use right function name.
Comment #3
bellagio commentedCould you tell me what i should expect after applying this patch? Will this let me add different address or is this a patch to develop more coding? i applied the patch, but i can't tell what has been changed.
Comment #4
bendiy commented@bellagio It just adds the ability for module developers to write hooks that modify what the address is.
Nothing changes unless you have a code that makes use of those alter hooks and modifies the address. The related issues could use these new hooks to do some of the things they are trying to do.
Comment #5
ultimike@bendiy,
I really like this patch (thanks for making our variable names a bit more consistent as well).
I'm willing to commit this, let's just have one or two more people test is out and report back that all is well.
Thanks,
-mike
Comment #6
joelpittetThis is great! I'd swap out property_exists() with isset() because it's more common and fast but that is super minor and drop the fancy = indenting because it's not so common for coding standards.
This allows for the ship_from address to changes based on order! That way we can set the other warehouse's address can be used depending on the destination and get a more accurate estimate!
@bendiy++
Comment #7
christiansanders commentedWe had some big problems trying to cleanly apply the patch to the current dev version of the commerce_ups_module. Hunk 4 of the .xml.inc file was the issue (the line being replaced was exactly the same...) so we removed the hunk and the patch applied cleanly. Here is new version of that patch.
Comment #8
joelpittetThis needs a re-roll but I've got commit access so we can get this in.
Comment #9
joelpittetedit: cross posted myself:S
Comment #10
niklaz commentedI can confirm that this works, however depending on measurement system when switching to another ship from address which uses different measurement system, UPS will return error instead of results.
example of error:
"This measurement system is not valid for the selected country"
Comment #11
joshmillerRerolled.
Comment #12
andyg5000Wow, this is an old one :) If it's still needed, I'm fine committing, but a few things first..
The api documentation doesn't match the function implementation.
I like the api documentation better than the implementation. Can we pass the address as alterable and the order wrapper as context (not by reference). I know it's an object, but it's a bit cleaner so that other devs don't go to town altering the order wrapper :)