solidus_active_shipping 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/.simplecov +5 -0
- data/.travis.yml +21 -0
- data/Gemfile +18 -0
- data/README.md +192 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/admin/product_packages/edit.js.coffee +4 -0
- data/app/assets/javascripts/admin/product_packages/index.js.coffee +28 -0
- data/app/assets/javascripts/admin/product_packages/new.js.coffee +7 -0
- data/app/assets/javascripts/spree/backend/solidus_active_shipping.js +0 -0
- data/app/assets/javascripts/spree/frontend/solidus_active_shipping.js +0 -0
- data/app/assets/stylesheets/spree/backend/solidus_active_shipping.css +0 -0
- data/app/assets/stylesheets/spree/frontend/solidus_active_shipping.css +0 -0
- data/app/controllers/spree/admin/active_shipping_settings_controller.rb +27 -0
- data/app/controllers/spree/admin/product_packages_controller.rb +17 -0
- data/app/controllers/spree/admin/products_controller_decorator.rb +12 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +11 -0
- data/app/controllers/spree/orders_controller_decorator.rb +11 -0
- data/app/models/spree/calculator/shipping/active_shipping/base.rb +208 -0
- data/app/models/spree/calculator/shipping/canada_post/base.rb +17 -0
- data/app/models/spree/calculator/shipping/canada_post/expedited.rb +11 -0
- data/app/models/spree/calculator/shipping/canada_post/parcel_surface.rb +11 -0
- data/app/models/spree/calculator/shipping/canada_post/priority_worldwide_intl.rb +12 -0
- data/app/models/spree/calculator/shipping/canada_post/regular.rb +11 -0
- data/app/models/spree/calculator/shipping/canada_post/small_packets_air.rb +11 -0
- data/app/models/spree/calculator/shipping/canada_post/small_packets_surface.rb +11 -0
- data/app/models/spree/calculator/shipping/canada_post/xpresspost.rb +11 -0
- data/app/models/spree/calculator/shipping/canada_post/xpresspost_international.rb +11 -0
- data/app/models/spree/calculator/shipping/fedex/base.rb +21 -0
- data/app/models/spree/calculator/shipping/fedex/express_saver.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/first_overnight.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/ground.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/ground_home_delivery.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/international_economy.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/international_economy_freight.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/international_first.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/international_ground.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/international_priority.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/international_priority_freight.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/international_priority_saturday_delivery.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/one_day_freight.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/one_day_freight_saturday_delivery.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/priority_overnight.rb +13 -0
- data/app/models/spree/calculator/shipping/fedex/priority_overnight_saturday_delivery.rb +11 -0
- data/app/models/spree/calculator/shipping/fedex/saver.rb +11 -0
- data/app/models/spree/calculator/shipping/fedex/standard_overnight.rb +11 -0
- data/app/models/spree/calculator/shipping/fedex/three_day_freight.rb +11 -0
- data/app/models/spree/calculator/shipping/fedex/three_day_freight_saturday_delivery.rb +11 -0
- data/app/models/spree/calculator/shipping/fedex/two_day.rb +11 -0
- data/app/models/spree/calculator/shipping/fedex/two_day_freight.rb +11 -0
- data/app/models/spree/calculator/shipping/fedex/two_day_freight_saturday_delivery.rb +11 -0
- data/app/models/spree/calculator/shipping/fedex/two_day_saturday_delivery.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/base.rb +30 -0
- data/app/models/spree/calculator/shipping/ups/express.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/ground.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/next_day_air.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/next_day_air_early_am.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/next_day_air_saver.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/saver.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/second_day_air.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/standard.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/three_day_select.rb +11 -0
- data/app/models/spree/calculator/shipping/ups/worldwide_expedited.rb +11 -0
- data/app/models/spree/calculator/shipping/usps/base.rb +84 -0
- data/app/models/spree/calculator/shipping/usps/express_mail.rb +19 -0
- data/app/models/spree/calculator/shipping/usps/express_mail_international.rb +46 -0
- data/app/models/spree/calculator/shipping/usps/first_class_mail_international.rb +31 -0
- data/app/models/spree/calculator/shipping/usps/first_class_mail_international_large_envelope.rb +31 -0
- data/app/models/spree/calculator/shipping/usps/first_class_mail_parcel.rb +28 -0
- data/app/models/spree/calculator/shipping/usps/first_class_package_international.rb +49 -0
- data/app/models/spree/calculator/shipping/usps/global_express_guaranteed.rb +48 -0
- data/app/models/spree/calculator/shipping/usps/media_mail.rb +19 -0
- data/app/models/spree/calculator/shipping/usps/priority_mail.rb +19 -0
- data/app/models/spree/calculator/shipping/usps/priority_mail_flat_rate_envelope.rb +19 -0
- data/app/models/spree/calculator/shipping/usps/priority_mail_international.rb +49 -0
- data/app/models/spree/calculator/shipping/usps/priority_mail_international_large_flat_rate_box.rb +43 -0
- data/app/models/spree/calculator/shipping/usps/priority_mail_international_medium_flat_rate_box.rb +43 -0
- data/app/models/spree/calculator/shipping/usps/priority_mail_international_small_flat_rate_box.rb +43 -0
- data/app/models/spree/calculator/shipping/usps/priority_mail_large_flat_rate_box.rb +19 -0
- data/app/models/spree/calculator/shipping/usps/priority_mail_medium_flat_rate_box.rb +19 -0
- data/app/models/spree/calculator/shipping/usps/priority_mail_small_flat_rate_box.rb +19 -0
- data/app/models/spree/calculator/shipping/usps/standard_post.rb +19 -0
- data/app/models/spree/content_item_decorator.rb +7 -0
- data/app/models/spree/line_item_decorator.rb +4 -0
- data/app/models/spree/package_builder.rb +114 -0
- data/app/models/spree/product_decorator.rb +10 -0
- data/app/models/spree/product_package.rb +10 -0
- data/app/models/spree/stock_location_decorator.rb +10 -0
- data/app/models/spree/variant_decorator.rb +3 -0
- data/app/overrides/spree/admin/shared/_configuration_menu/add_active_shipping_settings_tab.html.erb.deface +3 -0
- data/app/overrides/spree/admin/shared/_product_tabs/add_product_packages_tab.html.erb.deface +7 -0
- data/app/views/spree/admin/active_shipping_settings/edit.html.erb +92 -0
- data/app/views/spree/admin/product_packages/_form.html.erb +24 -0
- data/app/views/spree/admin/product_packages/edit.html.erb +15 -0
- data/app/views/spree/admin/product_packages/index.html.erb +46 -0
- data/app/views/spree/admin/product_packages/new.html.erb +15 -0
- data/config/locales/en.yml +93 -0
- data/config/locales/fr.yml +12 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20130107030221_create_product_packages.rb +12 -0
- data/lib/solidus_active_shipping.rb +3 -0
- data/lib/solidus_active_shipping/engine.rb +44 -0
- data/lib/spree/active_shipping_configuration.rb +24 -0
- data/lib/spree/shipping_error.rb +3 -0
- data/solidus_active_shipping.gemspec +33 -0
- data/spec/cassettes/Checkout/with_valid_shipping_address/does_not_break_the_per-item_shipping_method_calculator.yml +134 -0
- data/spec/cassettes/FedEx_calculators/with_Canadian_origin_address/Spree_Calculator_Shipping_Fedex_Ground/1_1_1_1.yml +48 -0
- data/spec/cassettes/FedEx_calculators/with_Canadian_origin_address/Spree_Calculator_Shipping_Fedex_InternationalEconomy/1_1_2_1.yml +48 -0
- data/spec/cassettes/FedEx_calculators/with_Canadian_origin_address/Spree_Calculator_Shipping_Fedex_InternationalFirst/1_1_3_1.yml +48 -0
- data/spec/cassettes/FedEx_calculators/with_Canadian_origin_address/Spree_Calculator_Shipping_Fedex_InternationalPriority/1_1_4_1.yml +48 -0
- data/spec/cassettes/FedEx_calculators/with_US_origin_address/Spree_Calculator_Shipping_Fedex_ExpressSaver/1_2_5_1.yml +48 -0
- data/spec/cassettes/FedEx_calculators/with_US_origin_address/Spree_Calculator_Shipping_Fedex_FirstOvernight/1_2_1_1.yml +48 -0
- data/spec/cassettes/FedEx_calculators/with_US_origin_address/Spree_Calculator_Shipping_Fedex_GroundHomeDelivery/1_2_6_1.yml +48 -0
- data/spec/cassettes/FedEx_calculators/with_US_origin_address/Spree_Calculator_Shipping_Fedex_PriorityOvernight/1_2_2_1.yml +48 -0
- data/spec/cassettes/FedEx_calculators/with_US_origin_address/Spree_Calculator_Shipping_Fedex_StandardOvernight/1_2_3_1.yml +48 -0
- data/spec/cassettes/FedEx_calculators/with_US_origin_address/Spree_Calculator_Shipping_Fedex_TwoDay/1_2_4_1.yml +48 -0
- data/spec/cassettes/UPS_calculators/with_Canadian_origin_address/Spree_Calculator_Shipping_Ups_Express/1_1_1_1.yml +103 -0
- data/spec/cassettes/UPS_calculators/with_Canadian_origin_address/Spree_Calculator_Shipping_Ups_Saver/1_1_3_1.yml +103 -0
- data/spec/cassettes/UPS_calculators/with_Canadian_origin_address/Spree_Calculator_Shipping_Ups_Standard/1_1_4_1.yml +103 -0
- data/spec/cassettes/UPS_calculators/with_Canadian_origin_address/Spree_Calculator_Shipping_Ups_ThreeDaySelect/1_1_5_1.yml +103 -0
- data/spec/cassettes/UPS_calculators/with_Canadian_origin_address/Spree_Calculator_Shipping_Ups_WorldwideExpedited/1_1_2_1.yml +103 -0
- data/spec/cassettes/UPS_calculators/with_US_origin_address/Spree_Calculator_Shipping_Ups_Ground/1_2_1_1.yml +103 -0
- data/spec/cassettes/UPS_calculators/with_US_origin_address/Spree_Calculator_Shipping_Ups_NextDayAir/1_2_2_1.yml +103 -0
- data/spec/cassettes/UPS_calculators/with_US_origin_address/Spree_Calculator_Shipping_Ups_NextDayAirEarlyAm/1_2_3_1.yml +103 -0
- data/spec/cassettes/UPS_calculators/with_US_origin_address/Spree_Calculator_Shipping_Ups_NextDayAirSaver/1_2_4_1.yml +103 -0
- data/spec/cassettes/UPS_calculators/with_US_origin_address/Spree_Calculator_Shipping_Ups_SecondDayAir/1_2_5_1.yml +103 -0
- data/spec/controllers/admin/active_shipping_settings_controller_spec.rb +38 -0
- data/spec/controllers/admin/product_packages_controller_spec.rb +36 -0
- data/spec/factories/order_factory_override.rb +46 -0
- data/spec/factories/product_package_factory.rb +9 -0
- data/spec/factories/state_factory_override.rb +28 -0
- data/spec/features/checkout_spec.rb +37 -0
- data/spec/fixtures/normal_rates_request.xml +2 -0
- data/spec/integrations/calculators/fedex_spec.rb +56 -0
- data/spec/integrations/calculators/ups_spec.rb +56 -0
- data/spec/lib/spree/active_shipping/bogus_carrier.rb +18 -0
- data/spec/lib/spree/calculator/shipping/bogus_calculator.rb +17 -0
- data/spec/models/active_shipping_calculator_spec.rb +182 -0
- data/spec/models/carriers/usps_calculator_spec.rb +72 -0
- data/spec/models/package_builder_spec.rb +173 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +80 -0
- data/spec/support/capybara.rb +24 -0
- data/spec/support/checkout_helper.rb +12 -0
- data/spec/support/feature_helper.rb +7 -0
- data/spec/support/package_helper.rb +9 -0
- data/spec/support/shared_contexts/checkout_setup.rb +12 -0
- data/spec/support/shared_contexts/package_setup.rb +34 -0
- data/spec/support/shared_contexts/shipping_carriers/fedex.rb +15 -0
- data/spec/support/shared_contexts/shipping_carriers/ups.rb +14 -0
- data/spec/support/shared_contexts/stock_location_setup.rb +26 -0
- data/spec/support/web_fixtures.rb +6 -0
- metadata +444 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require_dependency 'spree/calculator'
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Calculator::Shipping
|
|
5
|
+
module Ups
|
|
6
|
+
class Base < Spree::Calculator::Shipping::ActiveShipping::Base
|
|
7
|
+
def carrier
|
|
8
|
+
carrier_details = {
|
|
9
|
+
:login => Spree::ActiveShipping::Config[:ups_login],
|
|
10
|
+
:password => Spree::ActiveShipping::Config[:ups_password],
|
|
11
|
+
:key => Spree::ActiveShipping::Config[:ups_key],
|
|
12
|
+
:test => Spree::ActiveShipping::Config[:test_mode]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if shipper_number = Spree::ActiveShipping::Config[:shipper_number]
|
|
16
|
+
carrier_details.merge!(:origin_account => shipper_number)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
::ActiveShipping::UPS.new(carrier_details)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
protected
|
|
23
|
+
# weight limit in ounces http://www.ups.com/content/us/en/resources/prepare/oversize.html
|
|
24
|
+
def max_weight_for_country(country)
|
|
25
|
+
2400 # 150 lbs
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Calculator::Shipping
|
|
3
|
+
module Usps
|
|
4
|
+
class Base < Spree::Calculator::Shipping::ActiveShipping::Base
|
|
5
|
+
|
|
6
|
+
SERVICE_CODE_PREFIX ||= {
|
|
7
|
+
:international => 'intl',
|
|
8
|
+
:domestic => 'dom'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
def compute_package(package)
|
|
12
|
+
order = package.order
|
|
13
|
+
stock_location = package.stock_location
|
|
14
|
+
max_weight = get_max_weight(package)
|
|
15
|
+
|
|
16
|
+
origin = build_location(stock_location)
|
|
17
|
+
destination = build_location(order.ship_address)
|
|
18
|
+
|
|
19
|
+
rates_result = retrieve_rates_from_cache(package, origin, destination, max_weight)
|
|
20
|
+
|
|
21
|
+
return nil if rates_result.kind_of?(Spree::ShippingError)
|
|
22
|
+
return nil if rates_result.empty?
|
|
23
|
+
rate = rates_result[self.class.service_code]
|
|
24
|
+
|
|
25
|
+
return nil unless rate
|
|
26
|
+
rate = rate.to_f + (Spree::ActiveShipping::Config[:handling_fee].to_f || 0.0)
|
|
27
|
+
|
|
28
|
+
# divide by 100 since active_shipping rates are expressed as cents
|
|
29
|
+
return rate/100.0
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def carrier
|
|
33
|
+
carrier_details = {
|
|
34
|
+
:login => Spree::ActiveShipping::Config[:usps_login],
|
|
35
|
+
:test => Spree::ActiveShipping::Config[:test_mode]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
::ActiveShipping::USPS.new(carrier_details)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def retrieve_rates(origin, destination, shipment_packages)
|
|
44
|
+
begin
|
|
45
|
+
response = carrier.find_rates(origin, destination, shipment_packages)
|
|
46
|
+
# turn this beastly array into a nice little hash
|
|
47
|
+
service_code_prefix_key = response.params.keys.first == 'IntlRateV2Response' ? :international : :domestic
|
|
48
|
+
rates = response.rates.collect do |rate|
|
|
49
|
+
service_code = "#{SERVICE_CODE_PREFIX[service_code_prefix_key]}:#{rate.service_code}"
|
|
50
|
+
[service_code, rate.price]
|
|
51
|
+
end
|
|
52
|
+
rate_hash = Hash[*rates.flatten]
|
|
53
|
+
return rate_hash
|
|
54
|
+
rescue ::ActiveShipping::Error => e
|
|
55
|
+
if [::ActiveShipping::ResponseError].include?(e.class) && e.response.is_a?(::ActiveShipping::Response)
|
|
56
|
+
params = e.response.params
|
|
57
|
+
if params.has_key?("Response") && params["Response"].has_key?("Error") && params["Response"]["Error"].has_key?("ErrorDescription")
|
|
58
|
+
message = params["Response"]["Error"]["ErrorDescription"]
|
|
59
|
+
# Canada Post specific error message
|
|
60
|
+
elsif params.has_key?("eparcel") && params["eparcel"].has_key?("error") && params["eparcel"]["error"].has_key?("statusMessage")
|
|
61
|
+
message = e.response.params["eparcel"]["error"]["statusMessage"]
|
|
62
|
+
else
|
|
63
|
+
message = e.message
|
|
64
|
+
end
|
|
65
|
+
else
|
|
66
|
+
message = e.message
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
error = Spree::ShippingError.new("#{I18n.t(:shipping_error)}: #{message}")
|
|
70
|
+
Rails.cache.write @cache_key, error #write error to cache to prevent constant re-lookups
|
|
71
|
+
raise error
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
protected
|
|
77
|
+
# weight limit in ounces or zero (if there is no limit)
|
|
78
|
+
def max_weight_for_country(country)
|
|
79
|
+
1120 # 70 lbs
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Calculator::Shipping
|
|
3
|
+
module Usps
|
|
4
|
+
class ExpressMail < Spree::Calculator::Shipping::Usps::Base
|
|
5
|
+
def self.geo_group
|
|
6
|
+
:domestic
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.service_code
|
|
10
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:3" #Priority Mail Express {0}™
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.description
|
|
14
|
+
I18n.t("usps.express_mail")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Calculator::Shipping
|
|
3
|
+
module Usps
|
|
4
|
+
class ExpressMailInternational < Spree::Calculator::Shipping::Usps::Base
|
|
5
|
+
# http://pe.usps.com/text/imm/ab_001.htm .. http://pe.usps.com/text/imm/tz_028.htm
|
|
6
|
+
WEIGHT_LIMITS = {
|
|
7
|
+
"AL"=>1056, "DZ"=>704, "AD"=>1056, "AO"=>704, "AI"=>880, "AR"=>704, "AM"=>704, "AW"=>704, "AU"=>704, "AT"=>1056, "AZ"=>1120,
|
|
8
|
+
"BS"=>352, "BH"=>704, "BD"=>704, "BB"=>1056, "BY"=>704, "BE"=>1056, "BZ"=>1056, "BJ"=>1056, "BM"=>704, "BT"=>1056, "BO"=>1056,
|
|
9
|
+
"BA"=>1056, "BW"=>1056, "BR"=>1056, "BN"=>1056, "BG"=>1056, "BF"=>1120, "BI"=>1056, "KH"=>1056, "CM"=>704, "CA"=>1056, "CV"=>1056,
|
|
10
|
+
"KY"=>704, "CF"=>1056, "TD"=>1056, "CL"=>1056, "CN"=>1056, "CO"=>704, "CD"=>1056, "CG"=>1056, "CR"=>1056, "CI"=>1056, "HR"=>1056,
|
|
11
|
+
"CY"=>1120, "CZ"=>1120, "DK"=>1056, "DJ"=>704, "DM"=>704, "DO"=>1056, "EC"=>1056, "EG"=>704, "SV"=>1056, "GQ"=>704, "ER"=>1056,
|
|
12
|
+
"EE"=>1056, "ET"=>1056, "FO"=>704, "FJ"=>1056, "FI"=>1056, "FR"=>1056, "GF"=>1056, "PF"=>1056, "GA"=>1056, "GE"=>1056, "DE"=>1056,
|
|
13
|
+
"GH"=>1056, "GB"=>1056, "GR"=>1056, "GD"=>1056, "GP"=>1056, "GT"=>1056, "GN"=>704, "GW"=>704, "GY"=>1056, "HT"=>1056, "HN"=>704,
|
|
14
|
+
"HK"=>1056, "HU"=>1056, "IS"=>1056, "IN"=>1120, "ID"=>1056, "IQ"=>704, "IE"=>1056, "IL"=>704, "IT"=>1056, "JM"=>1056, "JP"=>1056,
|
|
15
|
+
"JO"=>1056, "KZ"=>1056, "KE"=>1120, "KR"=>1056, "KW"=>1056, "KG"=>1056, "LA"=>1056, "LV"=>1056, "LS"=>1056, "LR"=>704, "LI"=>1056,
|
|
16
|
+
"LT"=>1120, "LU"=>1056, "MO"=>1120, "MK"=>1056, "MG"=>1056, "MW"=>704, "MY"=>1056, "MV"=>1056, "ML"=>1056, "MT"=>704, "MQ"=>1056,
|
|
17
|
+
"MR"=>1056, "MU"=>1056, "MX"=>704, "MD"=>1120, "MN"=>1056, "MA"=>68, "MZ"=>1056, "NA"=>352, "NR"=>704, "NP"=>69, "NL"=>1056,
|
|
18
|
+
"AN"=>1056, "NC"=>1056, "NZ"=>1056, "NI"=>880, "NE"=>1120, "NG"=>1056, "NO"=>1056, "OM"=>1056, "PK"=>1056, "PA"=>1056, "PG"=>880,
|
|
19
|
+
"PY"=>880, "PE"=>1120, "PH"=>704, "PL"=>704, "PT"=>1056, "QA"=>1056, "RO"=>1120, "RU"=>1120, "RW"=>1056, "KN"=>1056, "LC"=>704,
|
|
20
|
+
"VC"=>704, "SM"=>1056, "SA"=>1056, "SN"=>1056, "RS"=>1056, "SC"=>1056, "SL"=>1056, "SG"=>1056, "SK"=>1056, "SI"=>1056, "SB"=>1056,
|
|
21
|
+
"ZA"=>1056, "ES"=>1056, "LK"=>1056, "SD"=>1056, "SZ"=>1056, "SE"=>1056, "CH"=>1056, "SY"=>704, "TW"=>33, "TJ"=>1056, "TZ"=>1056,
|
|
22
|
+
"TH"=>1056, "TG"=>1056, "TO"=>1056, "TT"=>1056, "TN"=>1056, "TR"=>1056, "TM"=>1056, "TC"=>1056, "UG"=>1056, "UA"=>704, "AE"=>1120,
|
|
23
|
+
"UY"=>704, "UZ"=>1056, "VU"=>880, "VA"=>1056, "VE"=>1056, "VN"=>1056, "WS"=>704, "YE"=>1056, "ZM"=>1056, "ZW"=>704
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def self.geo_group
|
|
27
|
+
:international
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.service_code
|
|
31
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:1" #Priority Mail Express International™
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.description
|
|
35
|
+
I18n.t("usps.express_mail_international")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
protected
|
|
39
|
+
# weight limit in ounces or zero (if there is no limit)
|
|
40
|
+
def max_weight_for_country(country)
|
|
41
|
+
return WEIGHT_LIMITS[country.iso]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Calculator::Shipping
|
|
3
|
+
module Usps
|
|
4
|
+
class FirstClassMailInternational < Spree::Calculator::Shipping::Usps::Base
|
|
5
|
+
WEIGHT_LIMITS = { "US" => 3.5 }
|
|
6
|
+
|
|
7
|
+
def self.geo_group
|
|
8
|
+
:international
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.service_code
|
|
12
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:13" #First-Class Mail® International Letter
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.description
|
|
16
|
+
I18n.t("usps.first_class_mail_international")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
protected
|
|
21
|
+
def max_weight_for_country(country)
|
|
22
|
+
# if weight in ounces > 3.5, then First Class Mail International is not available for the order
|
|
23
|
+
# https://www.usps.com/ship/first-class-international.htm
|
|
24
|
+
return WEIGHT_LIMITS[country.iso]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
data/app/models/spree/calculator/shipping/usps/first_class_mail_international_large_envelope.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Calculator::Shipping
|
|
3
|
+
module Usps
|
|
4
|
+
class FirstClassMailInternationalLargeEnvelope < Spree::Calculator::Shipping::Usps::Base
|
|
5
|
+
WEIGHT_LIMITS = { "US" => 64 }
|
|
6
|
+
|
|
7
|
+
def self.geo_group
|
|
8
|
+
:international
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.service_code
|
|
12
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:14" #First-Class Mail® International Large Envelope
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.description
|
|
16
|
+
I18n.t("usps.first_class_mail_international_large_envelope")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
protected
|
|
20
|
+
# weight limit in ounces or zero (if there is no limit)
|
|
21
|
+
def max_weight_for_country(country)
|
|
22
|
+
# if weight in ounces > 64, then First Class Mail International Large Envelope is not available for the order
|
|
23
|
+
# https://www.usps.com/ship/first-class-package-international-service.htm?
|
|
24
|
+
return WEIGHT_LIMITS[country.iso]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Calculator::Shipping
|
|
3
|
+
module Usps
|
|
4
|
+
class FirstClassMailParcel < Spree::Calculator::Shipping::Usps::Base
|
|
5
|
+
WEIGHT_LIMITS = { "US" => 13 }
|
|
6
|
+
|
|
7
|
+
def self.geo_group
|
|
8
|
+
:domestic
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.service_code
|
|
12
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:0" #First-Class Mail® Parcel
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.description
|
|
16
|
+
I18n.t("usps.first_class_mail_parcel")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
protected
|
|
20
|
+
def max_weight_for_country(country)
|
|
21
|
+
#if weight in ounces > 13, then First Class Mail is not available for the order
|
|
22
|
+
# https://www.usps.com/ship/first-class-international.htm
|
|
23
|
+
return WEIGHT_LIMITS[country.iso]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Calculator::Shipping
|
|
3
|
+
module Usps
|
|
4
|
+
class FirstClassPackageInternational < Spree::Calculator::Shipping::Usps::Base
|
|
5
|
+
def self.geo_group
|
|
6
|
+
:international
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.service_code
|
|
10
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:15" # First-Class Package International Service™
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.description
|
|
14
|
+
I18n.t("usps.first_class_package_international")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
# weight limit in ounces or zero (if there is no limit)
|
|
19
|
+
def max_weight_for_country(country)
|
|
20
|
+
64 # See limit of 4 pounds below.
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# SAMPLE API RESPONSE
|
|
24
|
+
# Pulled 21-Nov-2013
|
|
25
|
+
#{
|
|
26
|
+
#"ID": "15",
|
|
27
|
+
#"Pounds": "0",
|
|
28
|
+
#"Ounces": "11",
|
|
29
|
+
#"MailType": "Package",
|
|
30
|
+
#"Container": "RECTANGULAR",
|
|
31
|
+
#"Size": "REGULAR",
|
|
32
|
+
#"Width": "0.01",
|
|
33
|
+
#"Length": "0.01",
|
|
34
|
+
#"Height": "0.01",
|
|
35
|
+
#"Girth": "0.01",
|
|
36
|
+
#"Country": "SPAIN",
|
|
37
|
+
#"Postage": "14.90",
|
|
38
|
+
#"ExtraServices": null,
|
|
39
|
+
#"ValueOfContents": "0.00",
|
|
40
|
+
#"InsComment": "SERVICE",
|
|
41
|
+
#"SvcCommitments": "Varies by destination",
|
|
42
|
+
#"SvcDescription": "First-Class Package International Service<sup>™</sup>**",
|
|
43
|
+
#"MaxDimensions": "Other than rolls: Max. length 24\", max length, height and depth (thickness) combined 36\"<br>Rolls: Max. length 36\". Max length and twice the diameter combined 42\"",
|
|
44
|
+
#"MaxWeight": "4"
|
|
45
|
+
#}
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|