I have two UPS accounts and two shipping locations. I would like to create a rule to select the correct UPS method depending on country.

Should I create a duplicate module or is there a way to do this already?

Comments

andrew m riley’s picture

I need to do a very similar thing for one of my sites. I've been holding off on implementing the change until the entity as a field in the Address module has been completed.

The way I see it working is:

1) It would be a separate module
2) Admins could add a ship from address to the product
3) The new module would send the aplicable addresses to the shipping module and the shipping module would send out the requests. Add up the amounts etc.

The issues I think we'll face:
1) Most shipping modules try to send off the request to the API in one request. The shipping modules would have to be slightly modified to allow for more than one address.

Overall I think its a great idea and very needed!

chrisjlee’s picture

Title: Rules to use different UPS account based upon rules » Modify UPS account forms to allow different services
Component: Miscellaneous » Code
Status: Active » Needs review
StatusFileSize
new520 bytes

As per discussion with ryan today at drupalcon, the best possible solution at the moment would be to add a hook to alter shipping.

The discussion indicated that a hook was pertinent and necessary to be included as the UI layer can be added later. As that is best pratice.

I've attached a patch to attempt to do this. Looking forward to your review.

chrisjlee’s picture

sorry wrong file - let's try again

chrisjlee’s picture

one last time then bed. Added api file and attempted to document the hook

chrisjlee’s picture

arg. practice makes perfect i guess. working at getting better at patching. changed an embarrasing error

andrew m riley’s picture

Overall, this is possible (we would need to significantly work on how the module queries data and most likely split the current method out to a child module) but I do have a question about the other shipping methods.

1) Do the other shipping methods require other fields than ship from, ship to, weight and size?
2) This module does a rough box count approximation how would this work for things like UPS Freight?
3) Do the other services have additional costs like UPS standard does to deliver to residential addresses?

rtdean93’s picture

Thanks Andrew...

For our use case - we just need to have two instances of the fields currently employed by the admin form. So no new fields are needed.

To answer your questions specifically,
1) no
2) We are not using UPS Freight, so the approximate is fine.
3) Right now, we are using the same services as the existing module.

The fields important to have two options...
Ship From Address
UPS Account Number
UPS Password
UPS Key

Thanks Chris and Ryan for your help also.

chrisjlee’s picture

I misunderstood bobby's requirements the hook should actually placed in right in the function where the shipping services call is being made and then an xml file is generated.

This is actually what ryan was talking about. I had added a hook in the wrong function.

Thus, i've rerolled the patch.

andrew m riley’s picture

Whoops, I mixed up two issues. Don't mind the freight comments.

andyg5000’s picture

Would it be better to use drupal_alter to allow other modules to alter the request? If so, here's a patch.

andyg5000’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
StatusFileSize
new1.5 KB

Here's an updated patch that includes the order object so that you can actually do something with the rate request :)

I've also included the commerce_ups.api.php.

bendiy’s picture

Issue summary: View changes

I'm adding a hook over here #2293431: Abstract Ship To and Ship From addresses with hook_..._alter() that will let you modify the Ship From address based on the order.

bellagio’s picture

comment deleted

ultimike’s picture

andyg5000’s picture

Status: Needs review » Closed (duplicate)