spree_active_shipping
spree_active_shipping copied to clipboard
FedEx shipments are erroneously defaulted as Residential -> Residential, categorically disqualifying access to FedEx Ground services per FedEx business logic
Issue Description
I'd like to make FedEx Ground shipments via Spree. The :compute
method in our base class here generates ActiveShipping Location objects without specifying an :address_type, which means that ActiveShipping eventually treats them as Residential shipments :house_with_garden:. FedEx only delivers Ground shipments to businesses, reserving a separate "Ground Home Delivery" for residential destinations. We'd really like to be able to send appropriate B2B shipments :factory:.
First, spree_active_shipping
generates Location
objects without specifying :address_type
From the Base calculator:
def compute(object)
...
origin= Location.new(:country => Spree::ActiveShipping::Config[:origin_country],
:city => Spree::ActiveShipping::Config[:origin_city],
:state => Spree::ActiveShipping::Config[:origin_state],
:zip => Spree::ActiveShipping::Config[:origin_zip])
...
destination = Location.new(:country => addr.country.iso,
:state => (addr.state ? addr.state.abbr : addr.state_name),
:city => addr.city,
:zip => addr.zipcode)
Next, ActiveShipping instantiates the new Location objects with nil
for an :address_type
, which means it will never be :commercial?
From ActiveMerchant::Shipping::Location
def initialize(options = {})
...
self.address_type = options[:address_type]
end
...
def commercial?; @address_type == 'commercial' end
Finally, ActiveShipping's FedEx request defaults to 'Residential' in the absence of a specified :commercial?
:address_type
From ActiveMerchant::Shipping::Fedex:
address_node << XmlNode.new("Residential", true) unless location.commercial?
... and FedEx only returns residential shipping options as per their docs linked above.
Proposed Resolution
- When building the
origin
object, pass anaddress_type: 'commercial
to ActiveShipping. Spree stores are inherently commmercial. - When building the
destination
object, setaddres_type
to'commercial'
or'residential'
as appropriate. This leads to... - Add fields and form handling to allow Spree customers to specify whether they (or their addresses?) are individuals or businesses. Use the information stored there to properly feed the FedEx API.
- I'm looking into opening an issue with ActiveShipping to revisit the defaulting-to-residential behavior.
Thanks everyone! :thumbsup:
cc @jdugan
Amendment: We should probably let store admins decide whether their :origin
is commercial or residential via a checkbox in the active shipping admin template alongside the other origin settings such as origin zip code.
There has been some discussion to take origin from stock_location for shipping calcs. I know that UPS can determine if the address is residential or commerical. Do these exist in the API for Fedex so that we could set them on the fly during the shipment creation?
The FedEx API docs do claim they have an "Address Validation Service" which can - among other things - "Determine whether an address is business or residential to increase the accuracy of courtesy rate quotes. Applies to U.S. addresses only." I'm quoting this from a PDF I could only find after creating an account and logging in to their dev portal.
Edit: Filename is DeveloperGuide2012.pdf
@dpritchett is this still an issue?, I think I've read somewhere upstream over at Shopify/active_shipping that this was a problem
@dpritchett @mrpollo The address form already offers a company name field. If that field is filled in and we provide a company name, can we set the address type to commercial?
Another other option is to modify the address form and add a checkbox asking if the address is residential or commercial.
Note this will need to be done in base because UPS uses the same logic and will always default to residential.
I think it's more of a feature request at this point, but it is something that should be support one way or the other.
I like FineLine's take on it! If the company field is set, default to commercial. Personally I just hardcoded mine to commercial everywhere and I feel bad about it.