2017-01-23 09:30:31 +00:00
|
|
|
# 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
|
|
|
|
|
2019-01-15 17:41:41 +00:00
|
|
|
def total_weight(o)
|
|
|
|
weight = 0
|
|
|
|
o.line_items.each do |li|
|
|
|
|
weight += li.quantity * li.variant.weight
|
|
|
|
end
|
|
|
|
return weight
|
|
|
|
end
|
|
|
|
|
2017-01-23 09:30:31 +00:00
|
|
|
def extract_iso_code(o)
|
|
|
|
if o.kind_of?(Spree::Shipment)
|
|
|
|
return o.address.country.iso
|
|
|
|
end
|
|
|
|
return o.ship_address.country.iso
|
|
|
|
end
|
|
|
|
|
2019-01-15 17:41:41 +00:00
|
|
|
|
|
|
|
def postage_for_weight_DE(weight)
|
|
|
|
# Grossbrief Einschreiben: 3.95; Maxibrief Einschreiben: 5.10 / 7.30
|
|
|
|
if weight < 500
|
|
|
|
return 3.95
|
|
|
|
elsif weight < 1000
|
|
|
|
return 5.10
|
|
|
|
elsif weight < 2000
|
|
|
|
return 7.30
|
|
|
|
else
|
|
|
|
return 99999
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def postage_for_weight_INTL(weight)
|
|
|
|
# Warenpost International Unterschrift S: 6.20 / M: 9.50 / L: 19.50
|
|
|
|
if weight < 500
|
|
|
|
return 6.20
|
|
|
|
elsif weight < 1000
|
|
|
|
return 9.50
|
|
|
|
elsif weight < 2000
|
|
|
|
return 19.50
|
|
|
|
else
|
|
|
|
return 99999
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.available?(object)
|
|
|
|
# Letters have a maximum weight of 2kg
|
|
|
|
weight = total_weight(object)
|
|
|
|
if weight < 2000
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-23 09:30:31 +00:00
|
|
|
def compute(object)
|
|
|
|
# This could be more than an order but not right now
|
|
|
|
shipping_value = total_value_no_tax(object)
|
2019-01-15 17:41:41 +00:00
|
|
|
weight = total_weight(object)
|
2017-01-23 09:30:31 +00:00
|
|
|
iso_code = extract_iso_code(object)
|
|
|
|
|
|
|
|
if iso_code == 'DE'
|
2019-01-15 17:41:41 +00:00
|
|
|
base = postage_for_weight_DE(weight)
|
|
|
|
else
|
|
|
|
base = postage_for_weight_INTL(weight)
|
|
|
|
# We need to add insurance..
|
|
|
|
if shipping_value > 20
|
|
|
|
# Wert Intenational: 2.50 + 2 EUR je 100 EUR Haftungssumme
|
|
|
|
base += 2.5 + (((shipping_value.round / 100) + 1) * 2)
|
|
|
|
end
|
2017-01-23 11:18:19 +00:00
|
|
|
end
|
2019-01-15 17:41:41 +00:00
|
|
|
return base
|
2017-01-23 09:30:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|