Browse files

Namespace Updates - Ready for 1.0.0.beta

  • Loading branch information...
1 parent 1fc4eb1 commit 97ce6b2821abc8cb1fd1ae380a8032129970cd02 @LBRapid LBRapid committed Dec 1, 2011
Showing with 548 additions and 505 deletions.
  1. +2 −0 .gitignore
  2. +5 −0 Gemfile
  3. +13 −57 Rakefile
  4. +1 −0 Versionfile
  5. +2 −2 app/controllers/{ → spree}/admin/shipments_controller_decorator.rb
  6. +3 −3 app/controllers/{ → spree}/admin/shipping_methods_controller_decorator.rb
  7. +3 −3 app/controllers/{ → spree}/checkout_controller_decorator.rb
  8. +0 −129 app/models/calculator/active_shipping/base.rb
  9. +0 −8 app/models/calculator/fedex/base.rb
  10. +0 −5 app/models/calculator/fedex/express_saver.rb
  11. +0 −5 app/models/calculator/fedex/first_overnight.rb
  12. +0 −5 app/models/calculator/fedex/ground.rb
  13. +0 −5 app/models/calculator/fedex/ground_home_delivery.rb
  14. +0 −5 app/models/calculator/fedex/international_economy.rb
  15. +0 −5 app/models/calculator/fedex/international_economy_freight.rb
  16. +0 −5 app/models/calculator/fedex/international_first.rb
  17. +0 −5 app/models/calculator/fedex/international_ground.rb
  18. +0 −5 app/models/calculator/fedex/international_priority.rb
  19. +0 −5 app/models/calculator/fedex/international_priority_freight.rb
  20. +0 −5 app/models/calculator/fedex/international_priority_saturday_delivery.rb
  21. +0 −5 app/models/calculator/fedex/one_day_freight.rb
  22. +0 −5 app/models/calculator/fedex/one_day_freight_saturday_delivery.rb
  23. +0 −5 app/models/calculator/fedex/priority_overnight.rb
  24. +0 −5 app/models/calculator/fedex/priority_overnight_saturday_delivery.rb
  25. +0 −5 app/models/calculator/fedex/saver.rb
  26. +0 −5 app/models/calculator/fedex/standard_overnight.rb
  27. +0 −5 app/models/calculator/fedex/three_day_freight.rb
  28. +0 −5 app/models/calculator/fedex/three_day_freight_saturday_delivery.rb
  29. +0 −5 app/models/calculator/fedex/two_day.rb
  30. +0 −5 app/models/calculator/fedex/two_day_freight.rb
  31. +0 −5 app/models/calculator/fedex/two_day_freight_saturday_delivery.rb
  32. +0 −5 app/models/calculator/fedex/two_day_saturday_delivery.rb
  33. +0 −15 app/models/calculator/ups/base.rb
  34. +0 −5 app/models/calculator/ups/express.rb
  35. +0 −5 app/models/calculator/ups/ground.rb
  36. +0 −5 app/models/calculator/ups/next_day_air.rb
  37. +0 −5 app/models/calculator/ups/next_day_air_early_am.rb
  38. +0 −5 app/models/calculator/ups/next_day_air_saver.rb
  39. +0 −5 app/models/calculator/ups/saver.rb
  40. +0 −5 app/models/calculator/ups/second_day_air.rb
  41. +0 −5 app/models/calculator/ups/standard.rb
  42. +0 −5 app/models/calculator/ups/three_day_select.rb
  43. +0 −5 app/models/calculator/ups/worldwide_expedited.rb
  44. +0 −5 app/models/calculator/usps/base.rb
  45. +0 −5 app/models/calculator/usps/express_mail.rb
  46. +0 −5 app/models/calculator/usps/express_mail_international.rb
  47. +0 −5 app/models/calculator/usps/media_mail.rb
  48. +0 −5 app/models/calculator/usps/priority_mail.rb
  49. +0 −5 app/models/calculator/usps/priority_mail_flat_rate_envelope.rb
  50. +0 −5 app/models/calculator/usps/priority_mail_international.rb
  51. +0 −5 app/models/calculator/usps/priority_mail_international_large_flat_rate_box.rb
  52. +0 −5 app/models/calculator/usps/priority_mail_international_medium_flat_rate_box.rb
  53. +0 −5 app/models/calculator/usps/priority_mail_international_small_flat_rate_box.rb
  54. +0 −5 app/models/calculator/usps/priority_mail_large_flat_rate_box.rb
  55. +0 −5 app/models/calculator/usps/priority_mail_medium_flat_rate_boxes.rb
  56. +0 −5 app/models/calculator/usps/priority_mail_small_flat_rate_box.rb
  57. +131 −0 app/models/spree/calculator/active_shipping/base.rb
  58. +10 −0 app/models/spree/calculator/fedex/base.rb
  59. +7 −0 app/models/spree/calculator/fedex/express_saver.rb
  60. +7 −0 app/models/spree/calculator/fedex/first_overnight.rb
  61. +7 −0 app/models/spree/calculator/fedex/ground.rb
  62. +7 −0 app/models/spree/calculator/fedex/ground_home_delivery.rb
  63. +7 −0 app/models/spree/calculator/fedex/international_economy.rb
  64. +7 −0 app/models/spree/calculator/fedex/international_economy_freight.rb
  65. +7 −0 app/models/spree/calculator/fedex/international_first.rb
  66. +7 −0 app/models/spree/calculator/fedex/international_ground.rb
  67. +7 −0 app/models/spree/calculator/fedex/international_priority.rb
  68. +7 −0 app/models/spree/calculator/fedex/international_priority_freight.rb
  69. +7 −0 app/models/spree/calculator/fedex/international_priority_saturday_delivery.rb
  70. +7 −0 app/models/spree/calculator/fedex/one_day_freight.rb
  71. +7 −0 app/models/spree/calculator/fedex/one_day_freight_saturday_delivery.rb
  72. +7 −0 app/models/spree/calculator/fedex/priority_overnight.rb
  73. +7 −0 app/models/spree/calculator/fedex/priority_overnight_saturday_delivery.rb
  74. +7 −0 app/models/spree/calculator/fedex/saver.rb
  75. +7 −0 app/models/spree/calculator/fedex/standard_overnight.rb
  76. +7 −0 app/models/spree/calculator/fedex/three_day_freight.rb
  77. +7 −0 app/models/spree/calculator/fedex/three_day_freight_saturday_delivery.rb
  78. +7 −0 app/models/spree/calculator/fedex/two_day.rb
  79. +7 −0 app/models/spree/calculator/fedex/two_day_freight.rb
  80. +7 −0 app/models/spree/calculator/fedex/two_day_freight_saturday_delivery.rb
  81. +7 −0 app/models/spree/calculator/fedex/two_day_saturday_delivery.rb
  82. +16 −0 app/models/spree/calculator/ups/base.rb
  83. +7 −0 app/models/spree/calculator/ups/express.rb
  84. +7 −0 app/models/spree/calculator/ups/ground.rb
  85. +7 −0 app/models/spree/calculator/ups/next_day_air.rb
  86. +7 −0 app/models/spree/calculator/ups/next_day_air_early_am.rb
  87. +7 −0 app/models/spree/calculator/ups/next_day_air_saver.rb
  88. +7 −0 app/models/spree/calculator/ups/saver.rb
  89. +7 −0 app/models/spree/calculator/ups/second_day_air.rb
  90. +7 −0 app/models/spree/calculator/ups/standard.rb
  91. +7 −0 app/models/spree/calculator/ups/three_day_select.rb
  92. +7 −0 app/models/spree/calculator/ups/worldwide_expedited.rb
  93. +7 −0 app/models/spree/calculator/usps/base.rb
  94. +7 −0 app/models/spree/calculator/usps/express_mail.rb
  95. +7 −0 app/models/spree/calculator/usps/express_mail_international.rb
  96. +7 −0 app/models/spree/calculator/usps/media_mail.rb
  97. +7 −0 app/models/spree/calculator/usps/priority_mail.rb
  98. +7 −0 app/models/spree/calculator/usps/priority_mail_flat_rate_envelope.rb
  99. +7 −0 app/models/spree/calculator/usps/priority_mail_international.rb
  100. +7 −0 app/models/spree/calculator/usps/priority_mail_international_large_flat_rate_box.rb
  101. +7 −0 app/models/spree/calculator/usps/priority_mail_international_medium_flat_rate_box.rb
  102. +7 −0 app/models/spree/calculator/usps/priority_mail_international_small_flat_rate_box.rb
  103. +7 −0 app/models/spree/calculator/usps/priority_mail_large_flat_rate_box.rb
  104. +7 −0 app/models/spree/calculator/usps/priority_mail_medium_flat_rate_boxes.rb
  105. +7 −0 app/models/spree/calculator/usps/priority_mail_small_flat_rate_box.rb
  106. +0 −22 lib/spree/active_shipping/config.rb
  107. +1 −4 lib/{ → spree}/active_shipping_configuration.rb
  108. +2 −31 lib/spree_active_shipping.rb
  109. +36 −0 lib/spree_active_shipping/engine.rb
  110. +1 −1 spree_active_shipping.gemspec
View
2 .gitignore
@@ -1,3 +1,5 @@
spec/test_app
+spec/dummy
*.swp
Gemfile.lock
+.rvmrc
View
5 Gemfile
@@ -1,3 +1,8 @@
source :rubygems
gemspec
+
+gem 'sqlite3'
+
+gem 'spree', :git => 'git://github.com/spree/spree.git'
+gem 'rspec-rails', :group => [:development, :test]
View
70 Rakefile
@@ -1,63 +1,15 @@
# encoding: utf-8
-require 'rubygems'
-require 'rake'
-require 'rake/testtask'
+require 'bundler'
+Bundler::GemHelper.install_tasks
+Bundler.setup
-desc "Default Task"
-task :default => [ :spec ]
-
-gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
-if File.exists?(gemfile) && %w(rcov spec cucumber).include?(ARGV.first.to_s)
- require 'bundler'
- ENV['BUNDLE_GEMFILE'] = gemfile
- Bundler.setup
-
- require 'rspec/core/rake_task'
- RSpec::Core::RakeTask.new
-
- require 'cucumber/rake/task'
- Cucumber::Rake::Task.new do |t|
- t.cucumber_opts = %w{--format pretty}
- end
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new
- desc "Run specs with RCov"
- RSpec::Core::RakeTask.new(:rcov) do |t|
- t.rcov = true
- t.rcov_opts = %w{ --exclude gems\/,spec\/,features\/}
- t.verbose = true
- end
+require 'spree/core/testing_support/common_rake'
-end
-
-desc "Regenerates a rails 3 app for testing"
-task :test_app do
- SPREE_PATH = ENV['SPREE_PATH']
- raise "SPREE_PATH should be specified" unless SPREE_PATH
- require File.join(SPREE_PATH, 'lib/generators/spree/test_app_generator')
- class SpreeActiveShippingTestAppGenerator < Spree::Generators::TestAppGenerator
- def tweak_gemfile
- append_file 'Gemfile' do
-<<-gems
-gem 'spree_core', :path => '#{File.join(SPREE_PATH, 'core')}'
-gem 'spree_auth', :path => '#{File.join(SPREE_PATH, 'auth')}'
-gem 'spree_active_shipping', :path => '#{File.dirname(__FILE__)}'
-gems
- end
- end
-
- def install_gems
- inside "test_app" do
- run 'rake spree_core:install'
- run 'rake spree_auth:install'
- end
- end
-
- def migrate_db
- run_migrations
- end
- end
- SpreeActiveShippingTestAppGenerator.start
-end
+desc "Default Task"
+task :default => [ :spec ]
namespace :test_app do
desc 'Rebuild test and cucumber databases'
@@ -66,4 +18,8 @@ namespace :test_app do
end
end
-
+desc "Generates a dummy app for testing"
+task :test_app do
+ ENV['LIB_NAME'] = 'spree_active_shipping'
+ Rake::Task['common:test_app'].invoke
+end
View
1 Versionfile
@@ -1,3 +1,4 @@
+"1.0.x" => { :branch => 'master' }
"0.70.x" => { :version => '1.1.0', :ref => 'a85128c2ddd9b803ba5df58a2851d16ad54c9bd6' }
"0.60.x" => { :version => '1.0.3', :ref => 'cbfa92483fbfdd700eae44862308f949c199673e' }
"0.50.x" => { :version => '1.0.3', :ref => 'c582a227417ddc55ed7011b3208d37113ce87f09' }
View
4 ...s/admin/shipments_controller_decorator.rb → ...e/admin/shipments_controller_decorator.rb
@@ -1,5 +1,5 @@
# handle shipping errors gracefully on admin ui
-Admin::ShipmentsController.class_eval do
+Spree::Admin::ShipmentsController.class_eval do
rescue_from Spree::ShippingError, :with => :handle_shipping_error
private
@@ -8,4 +8,4 @@ def handle_shipping_error(e)
flash.now[:error] = e.message
render :action => "edit"
end
-end
+end
View
6 .../shipping_methods_controller_decorator.rb → .../shipping_methods_controller_decorator.rb
@@ -1,11 +1,11 @@
-Admin::ShippingMethodsController.class_eval do
+Spree::Admin::ShippingMethodsController.class_eval do
private
# overriding to return an array of Calculator objects instead of a Set
def load_data
- @available_zones = Zone.find :all, :order => :name
+ @available_zones = Spree::Zone.find :all, :order => :name
@calculators = []
- ShippingMethod.calculators.each {|calc|
+ Spree::ShippingMethod.calculators.each {|calc|
@calculators << eval(calc.name).new
}
@calculators = @calculators.sort_by(&:description)
View
6 ...trollers/checkout_controller_decorator.rb → ...rs/spree/checkout_controller_decorator.rb
@@ -1,11 +1,11 @@
# handle shipping errors gracefully during checkout
-CheckoutController.class_eval do
-
+Spree::CheckoutController.class_eval do
+
rescue_from Spree::ShippingError, :with => :handle_shipping_error
private
def handle_shipping_error(e)
flash[:error] = e.message
redirect_to checkout_state_path(:address)
end
-end
+end
View
129 app/models/calculator/active_shipping/base.rb
@@ -1,129 +0,0 @@
-# This is a base calculator for shipping calcualations using the ActiveShipping plugin. It is not intended to be
-# instantiated directly. Create sublcass for each specific shipping method you wish to support instead.
-module Calculator::ActiveShipping
-
- class Base < Calculator
- include ActiveMerchant::Shipping
-
- def self.service_name
- self.description
- end
-
- def compute(object)
- if object.is_a?(Array)
- order = object.first.order
- elsif object.is_a?(Shipment)
- order = object.order
- else
- order = object
- end
- 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])
-
- addr = order.ship_address
-
- destination = Location.new(:country => addr.country.iso,
- :state => (addr.state ? addr.state.abbr : addr.state_name),
- :city => addr.city,
- :zip => addr.zipcode)
-
- rates = Rails.cache.fetch(cache_key(order)) do
- rates = retrieve_rates(origin, destination, packages(order))
- end
-
- return nil if rates.empty?
- rate = rates[self.class.description]
- return nil unless rate
- rate = rate.to_f + (Spree::ActiveShipping::Config[:handling_fee].to_f || 0.0)
-
- # divide by 100 since active_shipping rates are expressed as cents
- return rate/100.0
- end
-
-
- def timing(line_items)
- order = line_items.first.order
- 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])
- addr = order.ship_address
- destination = Location.new(:country => addr.country.iso,
- :state => (addr.state ? addr.state.abbr : addr.state_name),
- :city => addr.city,
- :zip => addr.zipcode)
- timings = Rails.cache.fetch(cache_key(line_items)+"-timings") do
- timings = retrieve_timings(origin, destination, packages(order))
- end
- return nil if timings.nil? || !timings.is_a?(Hash) || timings.empty?
- return timings[self.description]
-
- end
-
- private
- def retrieve_rates(origin, destination, packages)
- begin
- response = carrier.find_rates(origin, destination, packages)
- # turn this beastly array into a nice little hash
- rate_hash = Hash[*response.rates.collect { |rate| [rate.service_name, rate.price] }.flatten]
- return rate_hash
- rescue ActiveMerchant::ActiveMerchantError => e
-
- if [ActiveMerchant::ResponseError, ActiveMerchant::Shipping::ResponseError].include? e.class
- params = e.response.params
- if params.has_key?("Response") && params["Response"].has_key?("Error") && params["Response"]["Error"].has_key?("ErrorDescription")
- message = params["Response"]["Error"]["ErrorDescription"]
- else
- message = e.message
- end
- else
- message = e.to_s
- end
-
- Rails.cache.write @cache_key, {} #write empty hash to cache to prevent constant re-lookups
-
- raise Spree::ShippingError.new("#{I18n.t(:shipping_error)}: #{message}")
- end
-
- end
-
-
- def retrieve_timings(origin, destination, packages)
- begin
- if carrier.respond_to?(:find_time_in_transit)
- response = carrier.find_time_in_transit(origin, destination, packages)
- return response
- end
- rescue ActiveMerchant::Shipping::ResponseError => re
- params = re.response.params
- if params.has_key?("Response") && params["Response"].has_key?("Error") && params["Response"]["Error"].has_key?("ErrorDescription")
- message = params["Response"]["Error"]["ErrorDescription"]
- elsee
- message = re.message
- end
- Rails.cache.write @cache_key+'-', {} #write empty hash to cache to prevent constant re-lookups
- raise Spree::ShippingError.new("#{I18n.t(:shipping_error)}: #{message}")
- end
- end
-
-
- private
-
- # Generates an array of Package objects based on the quantities and weights of the variants in the line items
- def packages(order)
- multiplier = Spree::ActiveShipping::Config[:unit_multiplier]
- weight = order.line_items.inject(0) do |weight, line_item|
- weight + (line_item.variant.weight ? (line_item.quantity * line_item.variant.weight * multiplier) : Spree::ActiveShipping::Config[:default_weight])
- end
- package = Package.new(weight, [], :units => Spree::ActiveShipping::Config[:units].to_sym)
- [package]
- end
-
- def cache_key(order)
- addr = order.ship_address
- @cache_key = "#{carrier.name}-#{order.number}-#{addr.country.iso}-#{addr.state ? addr.state.abbr : addr.state_name}-#{addr.city}-#{addr.zipcode}-#{order.line_items.map {|li| li.variant_id.to_s + "_" + li.quantity.to_s }.join("|")}".gsub(" ","")
- end
- end
-end
View
8 app/models/calculator/fedex/base.rb
@@ -1,8 +0,0 @@
-class Calculator::Fedex::Base < Calculator::ActiveShipping::Base
- def carrier
- ActiveMerchant::Shipping::FedEx.new(:key => Spree::ActiveShipping::Config[:fedex_key],
- :password => Spree::ActiveShipping::Config[:fedex_password],
- :account => Spree::ActiveShipping::Config[:fedex_account],
- :login => Spree::ActiveShipping::Config[:fedex_login])
- end
-end
View
5 app/models/calculator/fedex/express_saver.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::ExpressSaver < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.express_saver")
- end
-end
View
5 app/models/calculator/fedex/first_overnight.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::FirstOvernight < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.first_overnight")
- end
-end
View
5 app/models/calculator/fedex/ground.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::Ground < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.ground")
- end
-end
View
5 app/models/calculator/fedex/ground_home_delivery.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::GroundHomeDelivery < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.ground_home_delivery")
- end
-end
View
5 app/models/calculator/fedex/international_economy.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::InternationalEconomy < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.intl_economy")
- end
-end
View
5 app/models/calculator/fedex/international_economy_freight.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::InternationalEconomyFreight < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.intl_economy_freight")
- end
-end
View
5 app/models/calculator/fedex/international_first.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::InternationalFirst < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.intl_first")
- end
-end
View
5 app/models/calculator/fedex/international_ground.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::InternationalGround < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.intl_ground")
- end
-end
View
5 app/models/calculator/fedex/international_priority.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::InternationalPriority < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.intl_priority")
- end
-end
View
5 app/models/calculator/fedex/international_priority_freight.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::InternationalPriorityFreight < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.intl_priority_freight")
- end
-end
View
5 app/models/calculator/fedex/international_priority_saturday_delivery.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::InternationalPrioritySaturdayDelivery < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.intl_priority_saturday_delivery")
- end
-end
View
5 app/models/calculator/fedex/one_day_freight.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::OneDayFreight < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.one_day_freight")
- end
-end
View
5 app/models/calculator/fedex/one_day_freight_saturday_delivery.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::OneDayFreightSaturdayDelivery < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.one_day_freight_saturday_delivery")
- end
-end
View
5 app/models/calculator/fedex/priority_overnight.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::PriorityOvernight < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.priority_overnight")
- end
-end
View
5 app/models/calculator/fedex/priority_overnight_saturday_delivery.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::PriorityOvernightSaturdayDelivery < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.priority_overnight_saturday_delivery")
- end
-end
View
5 app/models/calculator/fedex/saver.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::Saver < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.saver")
- end
-end
View
5 app/models/calculator/fedex/standard_overnight.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::StandardOvernight < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.standard_overnight")
- end
-end
View
5 app/models/calculator/fedex/three_day_freight.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::ThreeDayFreight < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.three_day_freight")
- end
-end
View
5 app/models/calculator/fedex/three_day_freight_saturday_delivery.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::ThreeDayFreightSaturdayDelivery < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.three_day_freight_saturday_delivery")
- end
-end
View
5 app/models/calculator/fedex/two_day.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::TwoDay < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.two_day")
- end
-end
View
5 app/models/calculator/fedex/two_day_freight.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::TwoDayFreight < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.two_day_freight")
- end
-end
View
5 app/models/calculator/fedex/two_day_freight_saturday_delivery.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::TwoDayFreightSaturdayDelivery < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.two_day_freight_saturday_delivery")
- end
-end
View
5 app/models/calculator/fedex/two_day_saturday_delivery.rb
@@ -1,5 +0,0 @@
-class Calculator::Fedex::TwoDaySaturdayDelivery < Calculator::Fedex::Base
- def self.description
- I18n.t("fedex.two_day_saturday_delivery")
- end
-end
View
15 app/models/calculator/ups/base.rb
@@ -1,15 +0,0 @@
-class Calculator::Ups::Base < Calculator::ActiveShipping::Base
- def carrier
- if Spree::ActiveShipping::Config[:shipper_number].nil?
- ActiveMerchant::Shipping::UPS.new(:login => Spree::ActiveShipping::Config[:ups_login],
- :password => Spree::ActiveShipping::Config[:ups_password],
- :key => Spree::ActiveShipping::Config[:ups_key])
- else
- ActiveMerchant::Shipping::UPS.new(:login => Spree::ActiveShipping::Config[:ups_login],
- :password => Spree::ActiveShipping::Config[:ups_password],
- :key => Spree::ActiveShipping::Config[:ups_key],
- :origin_account => Spree::ActiveShipping::Config[:shipper_number])
- end
-
- end
-end
View
5 app/models/calculator/ups/express.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::Express < Calculator::Ups::Base
- def self.description
- I18n.t("ups.express")
- end
-end
View
5 app/models/calculator/ups/ground.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::Ground < Calculator::Ups::Base
- def self.description
- I18n.t("ups.ground")
- end
-end
View
5 app/models/calculator/ups/next_day_air.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::NextDayAir < Calculator::Ups::Base
- def self.description
- I18n.t("ups.next_day_air")
- end
-end
View
5 app/models/calculator/ups/next_day_air_early_am.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::NextDayAirEarlyAm < Calculator::Ups::Base
- def self.description
- I18n.t("ups.next_day_air_early_am")
- end
-end
View
5 app/models/calculator/ups/next_day_air_saver.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::NextDayAirSaver < Calculator::Ups::Base
- def self.description
- I18n.t("ups.next_day_air_saver")
- end
-end
View
5 app/models/calculator/ups/saver.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::Saver < Calculator::Ups::Base
- def self.description
- I18n.t("ups.saver")
- end
-end
View
5 app/models/calculator/ups/second_day_air.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::SecondDayAir < Calculator::Ups::Base
- def self.description
- I18n.t("ups.second_day_air")
- end
-end
View
5 app/models/calculator/ups/standard.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::Standard < Calculator::Ups::Base
- def self.description
- I18n.t("ups.standard")
- end
-end
View
5 app/models/calculator/ups/three_day_select.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::ThreeDaySelect < Calculator::Ups::Base
- def self.description
- I18n.t("ups.three_day_select")
- end
-end
View
5 app/models/calculator/ups/worldwide_expedited.rb
@@ -1,5 +0,0 @@
-class Calculator::Ups::WorldwideExpedited < Calculator::Ups::Base
- def self.description
- I18n.t("ups.worldwide_expedited")
- end
-end
View
5 app/models/calculator/usps/base.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::Base < Calculator::ActiveShipping::Base
- def carrier
- ActiveMerchant::Shipping::USPS.new(:login => Spree::ActiveShipping::Config[:usps_login])
- end
-end
View
5 app/models/calculator/usps/express_mail.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::ExpressMail < Calculator::Usps::Base
- def self.description
- I18n.t("usps.express_mail")
- end
-end
View
5 app/models/calculator/usps/express_mail_international.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::ExpressMailInternational < Calculator::Usps::Base
- def self.description
- I18n.t("usps.express_mail_intl")
- end
-end
View
5 app/models/calculator/usps/media_mail.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::MediaMail < Calculator::Usps::Base
- def self.description
- I18n.t("usps.media_mail")
- end
-end
View
5 app/models/calculator/usps/priority_mail.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::PriorityMail < Calculator::Usps::Base
- def self.description
- I18n.t("usps.priority_mail")
- end
-end
View
5 app/models/calculator/usps/priority_mail_flat_rate_envelope.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::PriorityMailFlatRateEnvelope < Calculator::Usps::Base
- def self.description
- I18n.t("usps.priority_mail_flat_rate_envelope")
- end
-end
View
5 app/models/calculator/usps/priority_mail_international.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::PriorityMailInternational < Calculator::Usps::Base
- def self.description
- I18n.t("usps.priority_mail_international")
- end
-end
View
5 app/models/calculator/usps/priority_mail_international_large_flat_rate_box.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::PriorityMailInternationalLargeFlatRateBox < Calculator::Usps::Base
- def self.description
- I18n.t("usps.priority_mail_international_large_flat_rate_box")
- end
-end
View
5 app/models/calculator/usps/priority_mail_international_medium_flat_rate_box.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::PriorityMailInternationalMediumFlatRateBox < Calculator::Usps::Base
- def self.description
- I18n.t("usps.priority_mail_international_medium_flat_rate_box")
- end
-end
View
5 app/models/calculator/usps/priority_mail_international_small_flat_rate_box.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::PriorityMailInternationalSmallFlatRateBox < Calculator::Usps::Base
- def self.description
- I18n.t("usps.priority_mail_international_small_flat_rate_box")
- end
-end
View
5 app/models/calculator/usps/priority_mail_large_flat_rate_box.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::PriorityMailLargeFlatRateBox < Calculator::Usps::Base
- def self.description
- I18n.t("usps.priority_mail_large_flat_rate_box")
- end
-end
View
5 app/models/calculator/usps/priority_mail_medium_flat_rate_boxes.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::PriorityMailMediumFlatRateBox < Calculator::Usps::Base
- def self.description
- I18n.t("usps.priority_mail_medium_flat_rate_box")
- end
-end
View
5 app/models/calculator/usps/priority_mail_small_flat_rate_box.rb
@@ -1,5 +0,0 @@
-class Calculator::Usps::PriorityMailSmallFlatRateBox < Calculator::Usps::Base
- def self.description
- I18n.t("usps.priority_mail_small_flat_rate_box")
- end
-end
View
131 app/models/spree/calculator/active_shipping/base.rb
@@ -0,0 +1,131 @@
+# This is a base calculator for shipping calcualations using the ActiveShipping plugin. It is not intended to be
+# instantiated directly. Create sublcass for each specific shipping method you wish to support instead.
+module Spree
+ module Calculator::ActiveShipping
+
+ class Base < Calculator
+ include ActiveMerchant::Shipping
+
+ def self.service_name
+ self.description
+ end
+
+ def compute(object)
+ if object.is_a?(Array)
+ order = object.first.order
+ elsif object.is_a?(Shipment)
+ order = object.order
+ else
+ order = object
+ end
+ 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])
+
+ addr = order.ship_address
+
+ destination = Location.new(:country => addr.country.iso,
+ :state => (addr.state ? addr.state.abbr : addr.state_name),
+ :city => addr.city,
+ :zip => addr.zipcode)
+
+ rates = Rails.cache.fetch(cache_key(order)) do
+ rates = retrieve_rates(origin, destination, packages(order))
+ end
+
+ return nil if rates.empty?
+ rate = rates[self.class.description]
+ return nil unless rate
+ rate = rate.to_f + (Spree::ActiveShipping::Config[:handling_fee].to_f || 0.0)
+
+ # divide by 100 since active_shipping rates are expressed as cents
+ return rate/100.0
+ end
+
+
+ def timing(line_items)
+ order = line_items.first.order
+ 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])
+ addr = order.ship_address
+ destination = Location.new(:country => addr.country.iso,
+ :state => (addr.state ? addr.state.abbr : addr.state_name),
+ :city => addr.city,
+ :zip => addr.zipcode)
+ timings = Rails.cache.fetch(cache_key(line_items)+"-timings") do
+ timings = retrieve_timings(origin, destination, packages(order))
+ end
+ return nil if timings.nil? || !timings.is_a?(Hash) || timings.empty?
+ return timings[self.description]
+
+ end
+
+ private
+ def retrieve_rates(origin, destination, packages)
+ begin
+ response = carrier.find_rates(origin, destination, packages)
+ # turn this beastly array into a nice little hash
+ rate_hash = Hash[*response.rates.collect { |rate| [rate.service_name, rate.price] }.flatten]
+ return rate_hash
+ rescue ActiveMerchant::ActiveMerchantError => e
+
+ if [ActiveMerchant::ResponseError, ActiveMerchant::Shipping::ResponseError].include? e.class
+ params = e.response.params
+ if params.has_key?("Response") && params["Response"].has_key?("Error") && params["Response"]["Error"].has_key?("ErrorDescription")
+ message = params["Response"]["Error"]["ErrorDescription"]
+ else
+ message = e.message
+ end
+ else
+ message = e.to_s
+ end
+
+ Rails.cache.write @cache_key, {} #write empty hash to cache to prevent constant re-lookups
+
+ raise Spree::ShippingError.new("#{I18n.t(:shipping_error)}: #{message}")
+ end
+
+ end
+
+
+ def retrieve_timings(origin, destination, packages)
+ begin
+ if carrier.respond_to?(:find_time_in_transit)
+ response = carrier.find_time_in_transit(origin, destination, packages)
+ return response
+ end
+ rescue ActiveMerchant::Shipping::ResponseError => re
+ params = re.response.params
+ if params.has_key?("Response") && params["Response"].has_key?("Error") && params["Response"]["Error"].has_key?("ErrorDescription")
+ message = params["Response"]["Error"]["ErrorDescription"]
+ elsee
+ message = re.message
+ end
+ Rails.cache.write @cache_key+'-', {} #write empty hash to cache to prevent constant re-lookups
+ raise Spree::ShippingError.new("#{I18n.t(:shipping_error)}: #{message}")
+ end
+ end
+
+
+ private
+
+ # Generates an array of Package objects based on the quantities and weights of the variants in the line items
+ def packages(order)
+ multiplier = Spree::ActiveShipping::Config[:unit_multiplier]
+ weight = order.line_items.inject(0) do |weight, line_item|
+ weight + (line_item.variant.weight ? (line_item.quantity * line_item.variant.weight * multiplier) : Spree::ActiveShipping::Config[:default_weight])
+ end
+ package = Package.new(weight, [], :units => Spree::ActiveShipping::Config[:units].to_sym)
+ [package]
+ end
+
+ def cache_key(order)
+ addr = order.ship_address
+ @cache_key = "#{carrier.name}-#{order.number}-#{addr.country.iso}-#{addr.state ? addr.state.abbr : addr.state_name}-#{addr.city}-#{addr.zipcode}-#{order.line_items.map {|li| li.variant_id.to_s + "_" + li.quantity.to_s }.join("|")}".gsub(" ","")
+ end
+ end
+ end
+end
View
10 app/models/spree/calculator/fedex/base.rb
@@ -0,0 +1,10 @@
+module Spree
+ class Calculator::Fedex::Base < Calculator::ActiveShipping::Base
+ def carrier
+ ActiveMerchant::Shipping::FedEx.new(:key => Spree::ActiveShipping::Config[:fedex_key],
+ :password => Spree::ActiveShipping::Config[:fedex_password],
+ :account => Spree::ActiveShipping::Config[:fedex_account],
+ :login => Spree::ActiveShipping::Config[:fedex_login])
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/express_saver.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::ExpressSaver < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.express_saver")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/first_overnight.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::FirstOvernight < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.first_overnight")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/ground.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::Ground < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.ground")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/ground_home_delivery.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::GroundHomeDelivery < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.ground_home_delivery")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/international_economy.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::InternationalEconomy < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.intl_economy")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/international_economy_freight.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::InternationalEconomyFreight < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.intl_economy_freight")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/international_first.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::InternationalFirst < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.intl_first")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/international_ground.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::InternationalGround < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.intl_ground")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/international_priority.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::InternationalPriority < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.intl_priority")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/international_priority_freight.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::InternationalPriorityFreight < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.intl_priority_freight")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/international_priority_saturday_delivery.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::InternationalPrioritySaturdayDelivery < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.intl_priority_saturday_delivery")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/one_day_freight.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::OneDayFreight < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.one_day_freight")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/one_day_freight_saturday_delivery.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::OneDayFreightSaturdayDelivery < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.one_day_freight_saturday_delivery")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/priority_overnight.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::PriorityOvernight < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.priority_overnight")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/priority_overnight_saturday_delivery.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::PriorityOvernightSaturdayDelivery < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.priority_overnight_saturday_delivery")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/saver.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::Saver < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.saver")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/standard_overnight.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::StandardOvernight < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.standard_overnight")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/three_day_freight.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::ThreeDayFreight < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.three_day_freight")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/three_day_freight_saturday_delivery.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::ThreeDayFreightSaturdayDelivery < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.three_day_freight_saturday_delivery")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/two_day.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::TwoDay < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.two_day")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/two_day_freight.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::TwoDayFreight < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.two_day_freight")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/two_day_freight_saturday_delivery.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::TwoDayFreightSaturdayDelivery < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.two_day_freight_saturday_delivery")
+ end
+ end
+end
View
7 app/models/spree/calculator/fedex/two_day_saturday_delivery.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Fedex::TwoDaySaturdayDelivery < Calculator::Fedex::Base
+ def self.description
+ I18n.t("fedex.two_day_saturday_delivery")
+ end
+ end
+end
View
16 app/models/spree/calculator/ups/base.rb
@@ -0,0 +1,16 @@
+module Spree
+ class Calculator::Ups::Base < Calculator::ActiveShipping::Base
+ def carrier
+ if Spree::ActiveShipping::Config[:shipper_number].nil?
+ ActiveMerchant::Shipping::UPS.new(:login => Spree::ActiveShipping::Config[:ups_login],
+ :password => Spree::ActiveShipping::Config[:ups_password],
+ :key => Spree::ActiveShipping::Config[:ups_key])
+ else
+ ActiveMerchant::Shipping::UPS.new(:login => Spree::ActiveShipping::Config[:ups_login],
+ :password => Spree::ActiveShipping::Config[:ups_password],
+ :key => Spree::ActiveShipping::Config[:ups_key],
+ :origin_account => Spree::ActiveShipping::Config[:shipper_number])
+ end
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/express.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::Express < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.express")
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/ground.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::Ground < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.ground")
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/next_day_air.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::NextDayAir < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.next_day_air")
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/next_day_air_early_am.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::NextDayAirEarlyAm < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.next_day_air_early_am")
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/next_day_air_saver.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::NextDayAirSaver < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.next_day_air_saver")
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/saver.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::Saver < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.saver")
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/second_day_air.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::SecondDayAir < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.second_day_air")
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/standard.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::Standard < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.standard")
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/three_day_select.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::ThreeDaySelect < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.three_day_select")
+ end
+ end
+end
View
7 app/models/spree/calculator/ups/worldwide_expedited.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Ups::WorldwideExpedited < Calculator::Ups::Base
+ def self.description
+ I18n.t("ups.worldwide_expedited")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/base.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::Base < Calculator::ActiveShipping::Base
+ def carrier
+ ActiveMerchant::Shipping::USPS.new(:login => Spree::ActiveShipping::Config[:usps_login])
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/express_mail.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::ExpressMail < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.express_mail")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/express_mail_international.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::ExpressMailInternational < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.express_mail_intl")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/media_mail.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::MediaMail < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.media_mail")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/priority_mail.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::PriorityMail < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.priority_mail")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/priority_mail_flat_rate_envelope.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::PriorityMailFlatRateEnvelope < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.priority_mail_flat_rate_envelope")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/priority_mail_international.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::PriorityMailInternational < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.priority_mail_international")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/priority_mail_international_large_flat_rate_box.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::PriorityMailInternationalLargeFlatRateBox < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.priority_mail_international_large_flat_rate_box")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/priority_mail_international_medium_flat_rate_box.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::PriorityMailInternationalMediumFlatRateBox < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.priority_mail_international_medium_flat_rate_box")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/priority_mail_international_small_flat_rate_box.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::PriorityMailInternationalSmallFlatRateBox < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.priority_mail_international_small_flat_rate_box")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/priority_mail_large_flat_rate_box.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::PriorityMailLargeFlatRateBox < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.priority_mail_large_flat_rate_box")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/priority_mail_medium_flat_rate_boxes.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::PriorityMailMediumFlatRateBox < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.priority_mail_medium_flat_rate_box")
+ end
+ end
+end
View
7 app/models/spree/calculator/usps/priority_mail_small_flat_rate_box.rb
@@ -0,0 +1,7 @@
+module Spree
+ class Calculator::Usps::PriorityMailSmallFlatRateBox < Calculator::Usps::Base
+ def self.description
+ I18n.t("usps.priority_mail_small_flat_rate_box")
+ end
+ end
+end
View
22 lib/spree/active_shipping/config.rb
@@ -1,22 +0,0 @@
-module Spree
- module ActiveShipping
- # Singleton class to access the shipping configuration object (ActiveShippingConfiguration.first by default) and it's preferences.
- #
- # Usage:
- # Spree::ActiveShipping::Config[:foo] # Returns the foo preference
- # Spree::ActiveShipping::Config[] # Returns a Hash with all the tax preferences
- # Spree::ActiveShipping::Config.instance # Returns the configuration object (ActiveShippingConfiguration.first)
- # Spree::ActiveShipping::Config.set(preferences_hash) # Set the active shipping preferences as especified in +preference_hash+
- class Config
- include Singleton
- include PreferenceAccess
-
- class << self
- def instance
- return nil unless ActiveRecord::Base.connection.tables.include?('configurations')
- ActiveShippingConfiguration.find_or_create_by_name("Default active_shipping configuration")
- end
- end
- end
- end
-end
View
5 lib/active_shipping_configuration.rb → lib/spree/active_shipping_configuration.rb
@@ -1,4 +1,4 @@
-class ActiveShippingConfiguration < Configuration
+class Spree::ActiveShippingConfiguration < Spree::Preferences::Configuration
preference :ups_login, :string, :default => "aunt_judy"
preference :ups_password, :string, :default => "secret"
@@ -20,7 +20,4 @@ class ActiveShippingConfiguration < Configuration
preference :units, :string, :default => "imperial"
preference :unit_multiplier, :integer, :default => 16 # 16 oz./lb - assumes variant weights are in lbs
preference :default_weight, :integer, :default => 0 # 16 oz./lb - assumes variant weights are in lbs
-
- validates_presence_of :name
- validates_uniqueness_of :name
end
View
33 lib/spree_active_shipping.rb
@@ -1,32 +1,3 @@
-require 'spree_core'
+require 'spree/core'
require 'active_shipping'
-
-module ActiveShippingExtension
- class Engine < Rails::Engine
- def self.activate
- Dir.glob(File.join(File.dirname(__FILE__), "../app/models/calculator/**/base.rb")) do |c|
- Rails.env.production? ? require(c) : load(c)
- end
-
- #Only required until following active_shipping commit is merged (add negotiated rates).
- #http://github.com/BDQ/active_shipping/commit/2f2560d53aa7264383e5a35deb7264db60eb405a
- ActiveMerchant::Shipping::UPS.send(:include, Spree::ActiveShipping::UpsOverride)
- end
-
- config.autoload_paths += %W(#{config.root}/lib)
- config.to_prepare &method(:activate).to_proc
-
- initializer "spree_active_shipping.register.calculators" do |app|
- Dir.glob(File.join(File.dirname(__FILE__), "../app/models/calculator/**/*.rb")) do |c|
- Rails.env.production? ? require(c) : load(c)
- end
-
- app.config.spree.calculators.shipping_methods.concat(
- Calculator::Fedex::Base.descendants +
- Calculator::Ups::Base.descendants +
- Calculator::Usps::Base.descendants
- )
- end
- end
-
-end
+require 'spree_active_shipping/engine'
View
36 lib/spree_active_shipping/engine.rb
@@ -0,0 +1,36 @@
+module Spree::ActiveShipping
+end
+module SpreeActiveShippingExtension
+ class Engine < Rails::Engine
+
+ initializer "spree.active_shipping.preferences", :after => "spree.environment" do |app|
+ Spree::ActiveShipping::Config = Spree::ActiveShippingConfiguration.new
+ end
+
+ def self.activate
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/models/spree/calculator/**/base.rb")) do |c|
+ Rails.env.production? ? require(c) : load(c)
+ end
+
+ #Only required until following active_shipping commit is merged (add negotiated rates).
+ #http://github.com/BDQ/active_shipping/commit/2f2560d53aa7264383e5a35deb7264db60eb405a
+ ActiveMerchant::Shipping::UPS.send(:include, Spree::ActiveShipping::UpsOverride)
+ end
+
+ config.autoload_paths += %W(#{config.root}/lib)
+ config.to_prepare &method(:activate).to_proc
+
+ initializer "spree_active_shipping.register.calculators" do |app|
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/models/spree/calculator/**/*.rb")) do |c|
+ Rails.env.production? ? require(c) : load(c)
+ end
+
+ app.config.spree.calculators.shipping_methods.concat(
+ Spree::Calculator::Fedex::Base.descendants +
+ Spree::Calculator::Ups::Base.descendants +
+ Spree::Calculator::Usps::Base.descendants
+ )
+ end
+ end
+
+end
View
2 spree_active_shipping.gemspec
@@ -17,6 +17,6 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.require_paths = ["lib"]
- s.add_dependency('spree_core', '>= 0.70.0')
+ s.add_dependency('spree_core', '>= 1.0.0.beta')
s.add_dependency('active_shipping', '0.9.13')
end

0 comments on commit 97ce6b2

Please sign in to comment.