combined weight + value based sysmocom_value_calculator (DHL Paket)
This commit is contained in:
parent
0917fbf514
commit
f84867df64
|
@ -98,56 +98,181 @@ module Spree
|
|||
"CN" => 1
|
||||
}.freeze()
|
||||
|
||||
def packages_price(value, limit, price_each)
|
||||
price = 0
|
||||
rest = value
|
||||
|
||||
# It is intended that a package reaching the limit is counted twice
|
||||
# Also a zero value should still be one package.
|
||||
while rest >= 0 do
|
||||
price += price_each
|
||||
rest -= limit
|
||||
def total_weight(o)
|
||||
weight = 0
|
||||
o.line_items.each do |li|
|
||||
weight += li.quantity + li.variant.weight
|
||||
end
|
||||
|
||||
price
|
||||
return weight
|
||||
end
|
||||
|
||||
# we choose pricing between 2kg and 5gk
|
||||
def price_germany(value)
|
||||
return packages_price(value, 500, 6.0)
|
||||
def insurance_cost_intl(value)
|
||||
# Service Hoeherversicherung International stand 1.1.2019
|
||||
if value <= 500
|
||||
return 0
|
||||
elsif value <= 1000
|
||||
return 14
|
||||
elsif value <= 2000
|
||||
return 28
|
||||
elsif value <= 3000
|
||||
return 42
|
||||
elsif value <= 4000
|
||||
return 56
|
||||
elsif value <= 5000
|
||||
return 70
|
||||
else
|
||||
return 99999
|
||||
end
|
||||
# maximum insured value 5000 EUR
|
||||
end
|
||||
|
||||
def insurance_cost_DE(value)
|
||||
if value <= 500
|
||||
return 0
|
||||
elsif value <= 2500
|
||||
return 6
|
||||
elsif value <= 25000
|
||||
return 18
|
||||
else
|
||||
return 99999
|
||||
end
|
||||
end
|
||||
|
||||
# we choose pricing between 2kg and 5kg
|
||||
def price_germany(value, weight)
|
||||
if weight < 2000
|
||||
price = 4.99
|
||||
elsif weight < 5000
|
||||
price = 5.99
|
||||
elsif weight < 10000
|
||||
price = 8.49
|
||||
elsif weight < 31500
|
||||
price = 16.49
|
||||
else
|
||||
price = 99999
|
||||
end
|
||||
return price + insurance_cost_DE(value)
|
||||
end
|
||||
|
||||
# We assume a 5kg package in all zones below
|
||||
def price_package_zone1(value)
|
||||
return packages_price(value, 500, 17.0)
|
||||
def price_package_zone1(value, weight)
|
||||
if weight < 2000
|
||||
price = 13.99
|
||||
elsif weight < 5000
|
||||
price = 15.99
|
||||
elsif weight < 10000
|
||||
price = 20.99
|
||||
elsif weight < 20000
|
||||
price = 21.99
|
||||
elsif weight < 31500
|
||||
price = 44.99
|
||||
else
|
||||
price = 99999
|
||||
end
|
||||
return price + insurance_cost_intl(value)
|
||||
end
|
||||
|
||||
def price_package_zone2(value)
|
||||
return packages_price(value, 500, 29)
|
||||
def price_package_zone2(value, weight)
|
||||
if weight < 5000
|
||||
price = 26.90
|
||||
elsif weight < 10000
|
||||
price = 34.99
|
||||
elsif weight < 20000
|
||||
price = 48.99
|
||||
elsif weight < 31500
|
||||
price = 55.99
|
||||
else
|
||||
price = 99999
|
||||
end
|
||||
return price + insurance_cost_intl(value)
|
||||
end
|
||||
|
||||
def price_package_zone3(value)
|
||||
return packages_price(value, 500, 30)
|
||||
def price_package_zone3(value, weight)
|
||||
if weight < 5000
|
||||
price = 29.99
|
||||
elsif weight < 10000
|
||||
price = 37.99
|
||||
elsif weight < 20000
|
||||
price = 52.99
|
||||
elsif weight < 31500
|
||||
price = 60.99
|
||||
else
|
||||
price = 99999
|
||||
end
|
||||
return price + insurance_cost_intl(value)
|
||||
end
|
||||
|
||||
def price_package_zone4(value)
|
||||
return packages_price(value, 500, 33)
|
||||
def price_package_zone4(value, weight)
|
||||
if weight < 5000
|
||||
price = 30.99
|
||||
elsif weight < 10000
|
||||
price = 37.99
|
||||
elsif weight < 20000
|
||||
price = 54.99
|
||||
else
|
||||
price = 99999
|
||||
end
|
||||
return price + insurance_cost_intl(value)
|
||||
end
|
||||
|
||||
def price_package_zone5(value)
|
||||
return packages_price(value, 500, 38)
|
||||
def price_package_zone5(value, weight)
|
||||
if weight < 5000
|
||||
price = 36.99
|
||||
elsif weight < 10000
|
||||
price = 53.99
|
||||
elsif weight < 20000
|
||||
price = 75.99
|
||||
elsif weight < 31500
|
||||
price = 105.99
|
||||
else
|
||||
price = 99999
|
||||
end
|
||||
return price + insurance_cost_intl(value)
|
||||
end
|
||||
|
||||
def price_package_zone6(value)
|
||||
return packages_price(value, 500, 40)
|
||||
def price_package_zone6(value, weight)
|
||||
if weight < 5000
|
||||
price = 37.99
|
||||
elsif weight < 10000
|
||||
price = 51.99
|
||||
elsif weight < 20000
|
||||
price = 71.99
|
||||
elsif weight < 31500
|
||||
price = 98.99
|
||||
else
|
||||
price = 99999
|
||||
end
|
||||
return price + insurance_cost_intl(value)
|
||||
end
|
||||
|
||||
def price_package_zone7(value)
|
||||
return packages_price(value, 500, 60)
|
||||
def price_package_zone7(value, weight)
|
||||
if weight < 5000
|
||||
price = 42.99
|
||||
elsif weight < 10000
|
||||
price = 58.99
|
||||
elsif weight < 20000
|
||||
price = 94.99
|
||||
elsif weight < 31500
|
||||
price = 125.99
|
||||
else
|
||||
price = 99999
|
||||
end
|
||||
return price + insurance_cost_intl(value)
|
||||
end
|
||||
|
||||
def price_package_zone8(value)
|
||||
return packages_price(value, 500, 63)
|
||||
def price_package_zone8(value, weight)
|
||||
if weight < 5000
|
||||
price = 45.99
|
||||
elsif weight < 10000
|
||||
price = 61.99
|
||||
elsif weight < 20000
|
||||
price = 100.99
|
||||
elsif weight < 31500
|
||||
price = 131.99
|
||||
else
|
||||
price = 99999
|
||||
end
|
||||
return price + insurance_cost_intl(value)
|
||||
end
|
||||
|
||||
|
||||
|
@ -166,27 +291,28 @@ module Spree
|
|||
def compute(object)
|
||||
# This could be more than an order but not right now
|
||||
shipping_value = total_value_no_tax(object)
|
||||
weight = total_weight(object)
|
||||
iso_code = extract_iso_code(object)
|
||||
|
||||
# Go through the zones by name...
|
||||
if iso_code == 'DE'
|
||||
return price_germany(shipping_value)
|
||||
return price_germany(shipping_value, weight)
|
||||
elsif ZONE1.has_key?(iso_code)
|
||||
return price_package_zone1(shipping_value)
|
||||
return price_package_zone1(shipping_value, weight)
|
||||
elsif ZONE2.has_key?(iso_code)
|
||||
return price_package_zone2(shipping_value)
|
||||
return price_package_zone2(shipping_value, weight)
|
||||
elsif ZONE3.has_key?(iso_code)
|
||||
return price_package_zone3(shipping_value)
|
||||
return price_package_zone3(shipping_value, weight)
|
||||
elsif ZONE4.has_key?(iso_code)
|
||||
return price_package_zone4(shipping_value)
|
||||
return price_package_zone4(shipping_value, weight)
|
||||
elsif ZONE5.has_key?(iso_code)
|
||||
return price_package_zone5(shipping_value)
|
||||
return price_package_zone5(shipping_value, weight)
|
||||
elsif ZONE6.has_key?(iso_code)
|
||||
return price_package_zone6(shipping_value)
|
||||
return price_package_zone6(shipping_value, weight)
|
||||
elsif ZONE7.has_key?(iso_code)
|
||||
return price_package_zone7(shipping_value)
|
||||
return price_package_zone7(shipping_value, weight)
|
||||
else
|
||||
return price_package_zone8(shipping_value)
|
||||
return price_package_zone8(shipping_value, weight)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue