spree_active_shipping icon indicating copy to clipboard operation
spree_active_shipping copied to clipboard

UPS needs street address to return commercial rates

Open isaacfreeman opened this issue 8 years ago • 0 comments

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?

isaacfreeman avatar Feb 25 '16 02:02 isaacfreeman