Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPS needs street address to return commercial rates #247

Open
isaacfreeman opened this issue Feb 25, 2016 · 0 comments
Open

UPS needs street address to return commercial rates #247

isaacfreeman opened this issue Feb 25, 2016 · 0 comments

Comments

@isaacfreeman
Copy link

UPS returns residential shipping rates by default, but if it has enough information to determine that a destination is a commercial address, it can return cheaper commercial shipping rates.

Spree::Calculator::Shipping::ActiveShipping::Base#build_location currently sends only country, state, city and zip. To get commercial rates UPS also needs the street address fields.

I have a client for whom low shipping rates are important, so I've made the following monkey patch:

Spree::Calculator::Shipping::ActiveShipping::Base.class_eval do
  def build_location(address)
    ActiveMerchant::Shipping::Location.new(
      address1:     address.address1,
      address2:     address.address2,
      country:      address.country.iso,
      company_name: address.respond_to?(:company) ? address.company : nil,
      state:        fetch_best_state_from_address(address),
      city:         address.city,
      zip:          address.zipcode
    )
  end
end

This seems to be working well, and is giving significantly better shipping rates for customers at commercial addresses. Should it be the standard behaviour for spree_active_shipping?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant