diff --git a/app/models/spree/calculator/sysmocom_mail_value_calculator.rb b/app/models/spree/calculator/sysmocom_mail_value_calculator.rb new file mode 100644 index 0000000..a8c348b --- /dev/null +++ b/app/models/spree/calculator/sysmocom_mail_value_calculator.rb @@ -0,0 +1,47 @@ +# AGPLv3 sysmocom s.f.m.c. GmbH + +module Spree + class Calculator::SysmocomMailValueCalculator < Calculator + + def self.description + I18n.t(:sysmocom_mail_value_based) + end + + def total_value_no_tax(o) + item_total = o.line_items.map(&:amount).sum + item_total + end + + def extract_iso_code(o) + if o.kind_of?(Spree::Shipment) + return o.address.country.iso + end + return o.ship_address.country.iso + end + + def compute(object) + # This could be more than an order but not right now + shipping_value = total_value_no_tax(object) + iso_code = extract_iso_code(object) + + base = 6.5 + if iso_code == 'DE' + base = 4.6 + end + + # We need to add insurance.. + if shipping_value < 30 + # Plain registered letter + return base + elsif shipping_value > 300 + # Stops making sense to send it.. + return 200 + end + + return base + (((shipping_value.round / 100) + 1) * 1.5) + end + + end +end + + diff --git a/config/locales/en.yml b/config/locales/en.yml index 5dd637e..c01aca5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,3 +4,4 @@ en: dhl_label: "DHL Label (CSV)" dhls: DHL sysmocom_value_based: sysmocom Value Based + sysmocom_mail_value_based: sysmocom Mail Value Based diff --git a/lib/sysmocom_dhl/engine.rb b/lib/sysmocom_dhl/engine.rb index a130ebb..5394cbd 100644 --- a/lib/sysmocom_dhl/engine.rb +++ b/lib/sysmocom_dhl/engine.rb @@ -20,7 +20,8 @@ module SysmocomDhl initializer "sysmocom_shipping_calculators" do |app| app.config.spree.calculators.shipping_methods += [ # ActiveSupport magic to search a model... - Spree::Calculator::SysmocomValueCalculator + Spree::Calculator::SysmocomValueCalculator, + Spree::Calculator::SysmocomMailValueCalculator ] end diff --git a/sysmocom_dhl.gemspec b/sysmocom_dhl.gemspec index f3acac1..a5300b3 100644 --- a/sysmocom_dhl.gemspec +++ b/sysmocom_dhl.gemspec @@ -12,8 +12,8 @@ Gem::Specification.new do |s| # s.homepage = 'http://www.rubyonrails.org' # s.rubyforge_project = 'actionmailer' - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + #s.files = `git ls-files`.split("\n") + #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.require_path = 'lib' s.requirements << 'none'