Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Canada Post national & international services

  • Loading branch information...
commit 6e85e036e6353d4081708e2f3f9a01910c19687c 1 parent acf5419
@jbourassa jbourassa authored j15e committed
View
16 app/models/spree/calculator/canada_post/base.rb
@@ -0,0 +1,16 @@
+require_dependency 'spree/calculator'
+
+module Spree
+ class Calculator < ActiveRecord::Base
+ module CanadaPost
+ class Base < Spree::Calculator::ActiveShipping::Base
+ def carrier
+ carrier_details = {
+ :login => Spree::ActiveShipping::Config[:canada_post_login],
+ }
+ ActiveMerchant::Shipping::CanadaPost.new(carrier_details)
+ end
+ end
+ end
+ end
+end
View
13 app/models/spree/calculator/canada_post/expedited.rb
@@ -0,0 +1,13 @@
+require_dependency 'spree/calculator'
+
+module Spree
+ class Calculator < ActiveRecord::Base
+ module CanadaPost
+ class Expedited < Calculator::CanadaPost::Base
+ def self.description
+ I18n.t("canada_post.expedited")
+ end
+ end
+ end
+ end
+end
View
14 app/models/spree/calculator/canada_post/parcel_surface.rb
@@ -0,0 +1,14 @@
+require_dependency 'spree/calculator'
+
+module Spree
+ class Calculator < ActiveRecord::Base
+ module CanadaPost
+ class ParcelSurface < Calculator::CanadaPost::Base
+ def self.description
+ I18n.t("canada_post.parcel_surface")
+ end
+ end
+ end
+ end
+end
+
View
14 app/models/spree/calculator/canada_post/priority_worldwide_intl.rb
@@ -0,0 +1,14 @@
+require_dependency 'spree/calculator'
+
+module Spree
+ class Calculator < ActiveRecord::Base
+ module CanadaPost
+ class PriorityWorldwideIntl < Calculator::CanadaPost::Base
+ def self.description
+ I18n.t("canada_post.priority_worldwide_intl")
+ end
+ end
+ end
+ end
+end
+
View
13 app/models/spree/calculator/canada_post/regular.rb
@@ -0,0 +1,13 @@
+require_dependency 'spree/calculator'
+
+module Spree
+ class Calculator < ActiveRecord::Base
+ module CanadaPost
+ class Regular < Calculator::CanadaPost::Base
+ def self.description
+ I18n.t("canada_post.regular")
+ end
+ end
+ end
+ end
+end
View
14 app/models/spree/calculator/canada_post/small_packets_air.rb
@@ -0,0 +1,14 @@
+require_dependency 'spree/calculator'
+
+module Spree
+ class Calculator < ActiveRecord::Base
+ module CanadaPost
+ class SmallPacketsAir < Calculator::CanadaPost::Base
+ def self.description
+ I18n.t("canada_post.small_packets_air")
+ end
+ end
+ end
+ end
+end
+
View
14 app/models/spree/calculator/canada_post/small_packets_surface.rb
@@ -0,0 +1,14 @@
+require_dependency 'spree/calculator'
+
+module Spree
+ class Calculator < ActiveRecord::Base
+ module CanadaPost
+ class SmallPacketsSurface < Calculator::CanadaPost::Base
+ def self.description
+ I18n.t("canada_post.small_packets_surface")
+ end
+ end
+ end
+ end
+end
+
View
14 app/models/spree/calculator/canada_post/xpresspost.rb
@@ -0,0 +1,14 @@
+require_dependency 'spree/calculator'
+
+module Spree
+ class Calculator < ActiveRecord::Base
+ module CanadaPost
+ class Xpresspost < Calculator::CanadaPost::Base
+ def self.description
+ I18n.t("canada_post.xpresspost")
+ end
+ end
+ end
+ end
+end
+
View
14 app/models/spree/calculator/canada_post/xpresspost_international.rb
@@ -0,0 +1,14 @@
+require_dependency 'spree/calculator'
+
+module Spree
+ class Calculator < ActiveRecord::Base
+ module CanadaPost
+ class XpresspostInternational < Calculator::CanadaPost::Base
+ def self.description
+ I18n.t("canada_post.xpresspost_international")
+ end
+ end
+ end
+ end
+end
+
View
9 config/locales/en.yml
@@ -48,4 +48,13 @@ en:
priority_mail_international_small_flat_rate_box: "USPS Priority Mail International Small Flat Rate Box"
priority_mail_international_medium_flat_rate_box: "USPS Priority Mail International Medium Flat Rate Box"
priority_mail_international_large_flat_rate_box: "USPS Priority Mail International Large Flat Rate Box"
+ canada_post:
+ regular: "Canada Post Regular"
+ expedited: "Canada Post Expedited"
+ xpresspost: "Canada Post Xpresspost"
+ priority_worldwide_intl: "Canada Post Priority Worldwide INTL"
+ xpresspost_international: "Canada Post XPressPost International"
+ small_packets_air: "Canada Post Small Packets Air"
+ parcel_surface: "Canada Post Parcel Surface"
+ small_packets_surface: "Canada Post Small Packets Surface"
shipping_error: "Shipping Error"
View
12 config/locales/fr.yml
@@ -0,0 +1,12 @@
+---
+fr:
+ canada_post:
+ regular: "Postes Canada Colis standard"
+ expedited: "Postes Canada Colis accélérés"
+ xpresspost: "Postes Canada Xpresspost"
+ priority_worldwide_intl: "Postes Canada Priorité Mondial INTL"
+ xpresspost_international: "Postes Canada XPressPost International"
+ small_packets_air: "Postes Canada Petits Colis - Air"
+ parcel_surface: "Postes Canada Colis Postaux - Surface"
+ small_packets_surface: "Postes Canada Petits Colis - Surface"
+ shipping_error: "Erreur de livraison"
View
2  lib/spree/active_shipping_configuration.rb
@@ -12,6 +12,8 @@ class Spree::ActiveShippingConfiguration < Spree::Preferences::Configuration
preference :usps_login, :string, :default => "aunt_judy"
+ preference :canada_post_login, :string, :default => "canada_post_login"
+
preference :origin_country, :string, :default => "US"
preference :origin_state, :string, :default => "PA"
preference :origin_city, :string, :default => "University Park"
View
3  lib/spree_active_shipping/engine.rb
@@ -32,7 +32,8 @@ def self.activate
app.config.spree.calculators.shipping_methods.concat(
Spree::Calculator::Fedex::Base.descendants +
Spree::Calculator::Ups::Base.descendants +
- Spree::Calculator::Usps::Base.descendants
+ Spree::Calculator::Usps::Base.descendants +
+ Spree::Calculator::CanadaPost::Base.descendants
)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.