solidus_active_shipping 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,48 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class GlobalExpressGuaranteed < 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
|
+
"AD"=>64,
|
8
|
+
"CD"=>1056,
|
9
|
+
"AE"=>1120, "AF"=>1120, "AG"=>1120, "AI"=>1120, "AL"=>1120, "AM"=>1120, "AN"=>1120, "AO"=>1120, "AR"=>1120, "AT"=>1120, "AU"=>1120,
|
10
|
+
"AW"=>1120, "AZ"=>1120, "BA"=>1120, "BB"=>1120, "BD"=>1120, "BE"=>1120, "BF"=>1120, "BG"=>1120, "BH"=>1120, "BI"=>1120, "BJ"=>1120,
|
11
|
+
"BM"=>1120, "BN"=>1120, "BR"=>1120, "BS"=>1120, "BT"=>1120, "BW"=>1120, "BY"=>1120, "BZ"=>1120, "CA"=>1120, "CG"=>1120, "CH"=>1120,
|
12
|
+
"CI"=>1120, "CL"=>1120, "CM"=>1120, "CN"=>1120, "CO"=>1120, "CR"=>1120, "CV"=>1120, "CY"=>1120, "CZ"=>1120, "DE"=>1120, "DJ"=>1120,
|
13
|
+
"DK"=>1120, "DM"=>1120, "DO"=>1120, "DZ"=>1120, "EC"=>1120, "EE"=>1120, "EG"=>1120, "ER"=>1120, "ES"=>1120, "ET"=>1120, "FI"=>1120,
|
14
|
+
"FJ"=>1120, "FO"=>1120, "FR"=>1120, "GA"=>1120, "GB"=>1120, "GD"=>1120, "GE"=>1120, "GF"=>1120, "GH"=>1120, "GI"=>1120, "GL"=>1120,
|
15
|
+
"GM"=>1120, "GN"=>1120, "GP"=>1120, "GR"=>1120, "GT"=>1120, "GY"=>1120, "HK"=>1120, "HN"=>1120, "HR"=>1120, "HT"=>1120, "HU"=>1120,
|
16
|
+
"ID"=>1120, "IE"=>1120, "IL"=>1120, "IN"=>1120, "IQ"=>1120, "IS"=>1120, "IT"=>1120, "JM"=>1120, "JO"=>1120, "JP"=>1120, "KE"=>1120,
|
17
|
+
"KG"=>1120, "KH"=>1120, "KM"=>1120, "KN"=>1120, "KR"=>1120, "KW"=>1120, "KY"=>1120, "KZ"=>1120, "LA"=>1120, "LB"=>1120, "LC"=>1120,
|
18
|
+
"LI"=>1120, "LK"=>1120, "LR"=>1120, "LS"=>1120, "LT"=>1120, "LU"=>1120, "LV"=>1120, "LY"=>1120, "MA"=>1120, "MD"=>1120, "ME"=>1120,
|
19
|
+
"MG"=>1120, "MK"=>1120, "ML"=>1120, "MN"=>1120, "MO"=>1120, "MP"=>1120, "MQ"=>1120, "MR"=>1120, "MS"=>1120, "MT"=>1120, "MU"=>1120,
|
20
|
+
"MV"=>1120, "MW"=>1120, "MX"=>1120, "MY"=>1120, "MZ"=>1120, "NA"=>1120, "NC"=>1120, "NE"=>1120, "NG"=>1120, "NI"=>1120, "NL"=>1120,
|
21
|
+
"NO"=>1120, "NP"=>1120, "NZ"=>1120, "OM"=>1120, "PA"=>1120, "PE"=>1120, "PF"=>1120, "PG"=>1120, "PH"=>1120, "PK"=>1120, "PL"=>1120,
|
22
|
+
"PT"=>1120, "PY"=>1120, "QA"=>1120, "RE"=>1120, "RO"=>1120, "RS"=>1120, "RU"=>1120, "RW"=>1120, "SA"=>1120, "SC"=>1120, "SE"=>1120,
|
23
|
+
"SG"=>1120, "SI"=>1120, "SK"=>1120, "SM"=>1120, "SN"=>1120, "SR"=>1120, "SV"=>1120, "SZ"=>1120, "TC"=>1120, "TD"=>1120, "TG"=>1120,
|
24
|
+
"TH"=>1120, "TN"=>1120, "TO"=>1120, "TR"=>1120, "TT"=>1120, "TW"=>1120, "TZ"=>1120, "UA"=>1120, "UG"=>1120, "UY"=>1120, "UZ"=>1120,
|
25
|
+
"VA"=>1120, "VC"=>1120, "VE"=>1120, "VG"=>1120, "VN"=>1120, "VU"=>1120, "WF"=>1120, "YE"=>1120, "ZA"=>1120, "ZM"=>1120, "ZW"=>1120
|
26
|
+
}
|
27
|
+
|
28
|
+
def self.geo_group
|
29
|
+
:international
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.service_code
|
33
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:4" #Global Express Guaranteed
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.description
|
37
|
+
I18n.t("usps.global_express_guaranteed")
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
# weight limit in ounces or zero (if there is no limit)
|
42
|
+
def max_weight_for_country(country)
|
43
|
+
return WEIGHT_LIMITS[country.iso]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class MediaMail < 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]}:6" #Media Mail®
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
I18n.t("usps.media_mail")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class PriorityMail < 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]}:1" #Priority Mail {0}™
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
I18n.t("usps.priority_mail")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class PriorityMailFlatRateEnvelope < 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]}:16" #Priority Mail {0}™ Flat Rate Envelope
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
I18n.t("usps.priority_mail_flat_rate_envelope")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class PriorityMailInternational < 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
|
+
"AI"=>352, "AG"=>352, "BS"=>352, "MM"=>352, "GQ"=>352, "JM"=>352, "PN"=>352,
|
8
|
+
"VC"=>352, "AL"=>704, "DZ"=>704, "AO"=>704, "AR"=>704, "AM"=>704, "AW"=>704, "BH"=>704, "BD"=>704, "BB"=>704, "BZ"=>704,
|
9
|
+
"BM"=>704, "BA"=>704, "VG"=>704, "BN"=>704, "CV"=>704, "KY"=>704, "TD"=>704, "CL"=>704, "KM"=>704, "CG"=>704, "DJ"=>704,
|
10
|
+
"DM"=>704, "DO"=>704, "SV"=>704, "ER"=>704, "FJ"=>704, "GA"=>704, "GE"=>704, "GI"=>704, "GR"=>704, "GD"=>704, "GT"=>704,
|
11
|
+
"GY"=>704, "HN"=>704, "HU"=>704, "IN"=>704, "ID"=>704, "IR"=>704, "IQ"=>704, "IL"=>704, "KZ"=>704, "KI"=>704, "KR"=>704,
|
12
|
+
"KG"=>704, "LA"=>704, "LS"=>704, "LR"=>704, "LY"=>704, "MG"=>704, "MR"=>704, "MU"=>704, "MX"=>704, "MS"=>704, "NA"=>704,
|
13
|
+
"NR"=>704, "NP"=>704, "NL"=>704, "AN"=>704, "OM"=>704, "PG"=>704, "PH"=>704, "PL"=>704, "RU"=>704, "KN"=>704, "SH"=>704,
|
14
|
+
"LC"=>704, "ST"=>704, "SB"=>704, "ES"=>704, "SD"=>704, "SR"=>704, "SZ"=>704, "TW"=>704, "TO"=>704, "TT"=>704, "TM"=>704,
|
15
|
+
"TC"=>704, "VU"=>704, "VA"=>704, "WS"=>704, "ZW"=>704, "HT"=>880, "TV"=>880, "AF"=>1056, "AD"=>1056, "AU"=>1056, "AT"=>1056,
|
16
|
+
"BY"=>1056, "BE"=>1056, "BJ"=>1056, "BT"=>1056, "BW"=>1056, "BR"=>1056, "BF"=>1056, "BI"=>1056, "CA"=>1056, "KH"=>1056, "CM"=>1056,
|
17
|
+
"CF"=>1056, "CN"=>1056, "CO"=>1056, "CD"=>1056, "CR"=>1056, "CI"=>1056, "HR"=>1056, "DK"=>1056, "EC"=>1056, "EG"=>1056, "ET"=>1056,
|
18
|
+
"FR"=>1056, "GF"=>1056, "PF"=>1056, "GM"=>1056, "GH"=>1056, "GB"=>1056, "MP"=>1056, "GL"=>1056, "GP"=>1056, "GN"=>1056, "GW"=>1056,
|
19
|
+
"HK"=>1056, "IE"=>1056, "IT"=>1056, "JP"=>1056, "JO"=>1056, "KW"=>1056, "LB"=>1056, "LI"=>1056, "LU"=>1056, "MW"=>1056, "MY"=>1056,
|
20
|
+
"MV"=>1056, "ML"=>1056, "MT"=>1056, "MQ"=>1056, "MN"=>1056, "MA"=>1056, "MZ"=>1056, "NC"=>1056, "NZ"=>1056, "NI"=>1056, "NG"=>1056,
|
21
|
+
"NO"=>1056, "PY"=>1056, "PT"=>1056, "RE"=>1056, "RW"=>1056, "PM"=>1056, "SM"=>1056, "SA"=>1056, "SN"=>1056, "SL"=>1056, "SG"=>1056,
|
22
|
+
"SK"=>1056, "SI"=>1056, "ZA"=>1056, "LK"=>1056, "SE"=>1056, "CH"=>1056, "TJ"=>1056, "TZ"=>1056, "TH"=>1056, "TN"=>1056, "TR"=>1056,
|
23
|
+
"UG"=>1056, "UA"=>1056, "UY"=>1056, "VE"=>1056, "WF"=>1056, "YE"=>1056, "ZM"=>1056, "AZ"=>1120, "BG"=>1120, "CY"=>1120, "CZ"=>1120,
|
24
|
+
"EE"=>1120, "FO"=>1120, "FI"=>1120, "DE"=>1120, "IS"=>1120, "KE"=>1120, "LV"=>1120, "LT"=>1120, "MO"=>1120, "MK"=>1120, "MD"=>1120,
|
25
|
+
"ME"=>1120, "NE"=>1120, "PK"=>1120, "PA"=>1120, "PE"=>1120, "QA"=>1120, "RO"=>1120, "RS"=>1120, "SC"=>1120, "SY"=>1120, "TG"=>1120,
|
26
|
+
"AE"=>1120, "UZ"=>1120, "VN"=>1120
|
27
|
+
}
|
28
|
+
|
29
|
+
def self.geo_group
|
30
|
+
:international
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.service_code
|
34
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:2" #Priority Mail International®
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.description
|
38
|
+
I18n.t("usps.priority_mail_international")
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
# weight limit in ounces or zero (if there is no limit)
|
43
|
+
def max_weight_for_country(country)
|
44
|
+
return WEIGHT_LIMITS[country.iso]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/app/models/spree/calculator/shipping/usps/priority_mail_international_large_flat_rate_box.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class PriorityMailInternationalLargeFlatRateBox < 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
|
+
AVAILABLE_COUNTRIES = [
|
7
|
+
"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AR", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE",
|
8
|
+
"BF", "BG", "BH", "BI", "BJ", "BM", "BN", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CD", "CF", "CG", "CH",
|
9
|
+
"CI", "CL", "CM", "CN", "CO", "CR", "CV", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG",
|
10
|
+
"ER", "ES", "ET", "FI", "FJ", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GH", "GI", "GL", "GM", "GN", "GP",
|
11
|
+
"GQ", "GR", "GT", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN", "IQ", "IR", "IS", "IT",
|
12
|
+
"JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK",
|
13
|
+
"LR", "LS", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MG", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR",
|
14
|
+
"MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NG", "NI", "NL", "NO", "NP", "NR", "NZ",
|
15
|
+
"OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PT", "PY", "QA", "RE", "RO", "RS", "RU", "RW",
|
16
|
+
"SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SK", "SL", "SM", "SN", "SR", "ST", "SV", "SY", "SZ", "TC",
|
17
|
+
"TD", "TG", "TH", "TJ", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UY", "UZ", "VA", "VC",
|
18
|
+
"VE", "VG", "VN", "VU", "WF", "WS", "YE", "ZA", "ZM", "ZW"
|
19
|
+
]
|
20
|
+
|
21
|
+
def self.geo_group
|
22
|
+
:international
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.service_code
|
26
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:11" #Priority Mail International® Large Flat Rate Box
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.description
|
30
|
+
I18n.t("usps.priority_mail_international_large_flat_rate_box")
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
# weight limit in ounces http://pe.usps.com/text/imm/immc2_011.htm
|
35
|
+
def max_weight_for_country(country)
|
36
|
+
# https://www.usps.com/ship/priority-mail-international-flat.htm?
|
37
|
+
return 320 if AVAILABLE_COUNTRIES.include? country.iso # 20lbs
|
38
|
+
nil # ex. AC, BO, CU, FK, KP, SO
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/app/models/spree/calculator/shipping/usps/priority_mail_international_medium_flat_rate_box.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class PriorityMailInternationalMediumFlatRateBox < 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
|
+
AVAILABLE_COUNTRIES = [
|
7
|
+
"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AR", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE",
|
8
|
+
"BF", "BG", "BH", "BI", "BJ", "BM", "BN", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CD", "CF", "CG", "CH",
|
9
|
+
"CI", "CL", "CM", "CN", "CO", "CR", "CV", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG",
|
10
|
+
"ER", "ES", "ET", "FI", "FJ", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GH", "GI", "GL", "GM", "GN", "GP",
|
11
|
+
"GQ", "GR", "GT", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN", "IQ", "IR", "IS", "IT",
|
12
|
+
"JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK",
|
13
|
+
"LR", "LS", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MG", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR",
|
14
|
+
"MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NG", "NI", "NL", "NO", "NP", "NR", "NZ",
|
15
|
+
"OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PT", "PY", "QA", "RE", "RO", "RS", "RU", "RW",
|
16
|
+
"SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SK", "SL", "SM", "SN", "SR", "ST", "SV", "SY", "SZ", "TC",
|
17
|
+
"TD", "TG", "TH", "TJ", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UY", "UZ", "VA", "VC",
|
18
|
+
"VE", "VG", "VN", "VU", "WF", "WS", "YE", "ZA", "ZM", "ZW"
|
19
|
+
]
|
20
|
+
|
21
|
+
def self.geo_group
|
22
|
+
:international
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.service_code
|
26
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:9" #Priority Mail International® Medium Flat Rate Box
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.description
|
30
|
+
I18n.t("usps.priority_mail_international_medium_flat_rate_box")
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
# weight limit in ounces http://pe.usps.com/text/imm/immc2_011.htm
|
35
|
+
def max_weight_for_country(country)
|
36
|
+
# https://www.usps.com/ship/priority-mail-international-flat.htm?
|
37
|
+
return 320 if AVAILABLE_COUNTRIES.include? country.iso # 20lbs
|
38
|
+
nil # ex. AC, BO, CU, FK, KP, SO
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/app/models/spree/calculator/shipping/usps/priority_mail_international_small_flat_rate_box.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class PriorityMailInternationalSmallFlatRateBox < 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
|
+
AVAILABLE_COUNTRIES = [
|
7
|
+
"AC", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AR", "AT", "AU", "AW", "AZ", "BA", "BB", "BD",
|
8
|
+
"BE", "BF", "BG", "BH", "BI", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CD", "CF",
|
9
|
+
"CG", "CH", "CI", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ",
|
10
|
+
"EC", "EE", "EG", "ER", "ES", "ET", "FI", "FJ", "FK", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GH", "GI",
|
11
|
+
"GL", "GM", "GN", "GP", "GQ", "GR", "GT", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN",
|
12
|
+
"IQ", "IR", "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", "KW", "KY", "KZ", "LA",
|
13
|
+
"LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MG", "MK", "ML", "MM", "MN",
|
14
|
+
"MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NG", "NI", "NL",
|
15
|
+
"NO", "NP", "NR", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PT", "PY", "QA", "RE",
|
16
|
+
"RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SK", "SL", "SM", "SN", "SR", "ST",
|
17
|
+
"SV", "SY", "SZ", "TC", "TD", "TG", "TH", "TJ", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG",
|
18
|
+
"UY", "UZ", "VA", "VC", "VE", "VG", "VN", "VU", "WF", "WS", "YE", "ZA", "ZM", "ZW"
|
19
|
+
]
|
20
|
+
|
21
|
+
def self.geo_group
|
22
|
+
:international
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.service_code
|
26
|
+
"#{SERVICE_CODE_PREFIX[geo_group]}:16" #Priority Mail International® Small Flat Rate Box**
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.description
|
30
|
+
I18n.t("usps.priority_mail_international_small_flat_rate_box")
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
# weight limit in ounces http://pe.usps.com/text/imm/immc2_011.htm
|
35
|
+
def max_weight_for_country(country)
|
36
|
+
# https://www.usps.com/ship/priority-mail-international-flat.htm?
|
37
|
+
return 64 if AVAILABLE_COUNTRIES.include? country.iso # 4lbs
|
38
|
+
nil # ex. North Korea, Somalia, etc.
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class PriorityMailLargeFlatRateBox < 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]}:22" #Priority Mail {0}™ Large Flat Rate Box
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
I18n.t("usps.priority_mail_large_flat_rate_box")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class PriorityMailMediumFlatRateBox < 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]}:17" #Priority Mail {0}™ Medium Flat Rate Box
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
I18n.t("usps.priority_mail_medium_flat_rate_box")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class PriorityMailSmallFlatRateBox < 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]}:28" #Priority Mail {0}™ Small Flat Rate Box
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
I18n.t("usps.priority_mail_small_flat_rate_box")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Calculator::Shipping
|
3
|
+
module Usps
|
4
|
+
class StandardPost < 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]}:4" #Standard Post
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
I18n.t("usps.standard_post")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Spree
|
2
|
+
class PackageBuilder
|
3
|
+
attr_accessor :max_weight
|
4
|
+
|
5
|
+
def process(solidus_package, max_weight)
|
6
|
+
# We compute and set the max_weight once, at the beginning of the process
|
7
|
+
@max_weight = max_weight
|
8
|
+
to_packages(solidus_package)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# Configuration
|
14
|
+
def units
|
15
|
+
Spree::ActiveShipping::Config[:units].to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
def multiplier
|
19
|
+
Spree::ActiveShipping::Config[:unit_multiplier]
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_weight
|
23
|
+
Spree::ActiveShipping::Config[:default_weight]
|
24
|
+
end
|
25
|
+
|
26
|
+
def convert_package_to_weights_array(product_with_product_packages)
|
27
|
+
weights = product_with_product_packages.map do |content_item|
|
28
|
+
item_weight = content_item.weight
|
29
|
+
item_weight = default_weight if item_weight <= 0
|
30
|
+
item_weight *= multiplier
|
31
|
+
|
32
|
+
if (item_weight > max_weight) && max_weight > 0
|
33
|
+
raise Spree::ShippingError, "#{I18n.t(:shipping_error)}: The maximum per package weight for the selected service from the selected country is #{max_weight} ounces."
|
34
|
+
end
|
35
|
+
|
36
|
+
item_weight
|
37
|
+
end
|
38
|
+
|
39
|
+
weights.compact
|
40
|
+
end
|
41
|
+
|
42
|
+
# Used for calculating Dimensional Weight pricing.
|
43
|
+
# Override in your own extensions to compute package dimensions,
|
44
|
+
# or just leave this alone to keep the default behavior.
|
45
|
+
# Sample output: [9, 6, 3]
|
46
|
+
def convert_package_to_dimensions_array(_package)
|
47
|
+
[]
|
48
|
+
end
|
49
|
+
|
50
|
+
def convert_package_to_item_packages_array(product_with_no_product_packages)
|
51
|
+
packages = []
|
52
|
+
|
53
|
+
product_with_no_product_packages.each do |content_item|
|
54
|
+
variant = content_item.variant
|
55
|
+
quantity = content_item.quantity
|
56
|
+
product = variant.product
|
57
|
+
|
58
|
+
product.product_packages.each do |product_package|
|
59
|
+
if product_package.weight.to_f <= max_weight || max_weight == 0
|
60
|
+
quantity.times do
|
61
|
+
packages << product_package
|
62
|
+
end
|
63
|
+
else
|
64
|
+
raise Spree::ShippingError, "#{I18n.t(:shipping_error)}: The maximum per package weight for the selected service from the selected country is #{max_weight} ounces."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
packages
|
70
|
+
end
|
71
|
+
|
72
|
+
# Generates an array of Package objects based on the quantities and weights of the variants in the line items
|
73
|
+
def to_packages(solidus_package)
|
74
|
+
active_shipping_packages = []
|
75
|
+
|
76
|
+
product_with_product_packages = []
|
77
|
+
product_with_no_product_packages = []
|
78
|
+
# Product with no associated product packages will be combined in packages based on weight
|
79
|
+
# Product with associated product packages will be added individually based on their attributes
|
80
|
+
solidus_package.contents.each do |content_item|
|
81
|
+
if content_item.variant_has_product_packages?
|
82
|
+
product_with_product_packages << content_item
|
83
|
+
else
|
84
|
+
product_with_no_product_packages << content_item
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
weights = convert_package_to_weights_array(product_with_no_product_packages)
|
89
|
+
dimensions = convert_package_to_dimensions_array(solidus_package)
|
90
|
+
item_specific_packages = convert_package_to_item_packages_array(product_with_product_packages)
|
91
|
+
|
92
|
+
if max_weight <= 0
|
93
|
+
active_shipping_packages << ::ActiveShipping::Package.new(weights.sum, dimensions, units: units) unless weights.empty?
|
94
|
+
else
|
95
|
+
package_weight = 0
|
96
|
+
weights.each do |content_weight|
|
97
|
+
if package_weight + content_weight <= max_weight
|
98
|
+
package_weight += content_weight
|
99
|
+
else
|
100
|
+
active_shipping_packages << ::ActiveShipping::Package.new(package_weight, dimensions, units: units)
|
101
|
+
package_weight = content_weight
|
102
|
+
end
|
103
|
+
end
|
104
|
+
active_shipping_packages << ::ActiveShipping::Package.new(package_weight, dimensions, units: units) if package_weight > 0
|
105
|
+
end
|
106
|
+
|
107
|
+
item_specific_packages.each do |product_package|
|
108
|
+
active_shipping_packages << ::ActiveShipping::Package.new(product_package.weight * multiplier, [product_package.length, product_package.width, product_package.height], units: units)
|
109
|
+
end
|
110
|
+
|
111
|
+
active_shipping_packages
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|