Compare commits
2 Commits
master
...
1-2-stable
Author | SHA1 | Date |
---|---|---|
Harald Welte | 97335a298e | |
Harald Welte | 52de319def |
|
@ -1,121 +0,0 @@
|
||||||
# AGPLv3 sysmocom s.f.m.c. GmbH
|
|
||||||
|
|
||||||
module Spree
|
|
||||||
class Calculator::SysmocomScBaseCalculator < Calculator
|
|
||||||
|
|
||||||
def total_value_no_tax(o)
|
|
||||||
item_total = o.line_items.map(&:amount).sum
|
|
||||||
item_total
|
|
||||||
end
|
|
||||||
|
|
||||||
def total_weight(o)
|
|
||||||
weight = 0
|
|
||||||
o.line_items.each do |li|
|
|
||||||
weight += li.quantity * li.variant.weight
|
|
||||||
end
|
|
||||||
return weight
|
|
||||||
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 extract_dst_dadr(o)
|
|
||||||
if o.kind_of?(Spree::Shipment)
|
|
||||||
return o.address
|
|
||||||
end
|
|
||||||
return o.ship_address
|
|
||||||
end
|
|
||||||
|
|
||||||
def cbrt(x)
|
|
||||||
return x ** (1.0/3)
|
|
||||||
end
|
|
||||||
|
|
||||||
def estimate_dimensions(weight_kg, density_kg_per_dm3)
|
|
||||||
volume_dm3 = weight_kg.to_f / density_kg_per_dm3.to_f
|
|
||||||
volume_cm3 = 1000.0 * volume_dm3
|
|
||||||
# assuming l=3x, w=2x, h1x -> x=6
|
|
||||||
x = cbrt(volume_cm3 / 6)
|
|
||||||
return 3.0 * x, 2.0 * x, 1.0 * x
|
|
||||||
end
|
|
||||||
|
|
||||||
def sc_compute(carrier, service, object)
|
|
||||||
# This could be more than an order but not right now
|
|
||||||
weight = total_weight(object)
|
|
||||||
dst = extract_dst_addr(object)
|
|
||||||
length, width, height = estimate_dimensions(weight, 0.5)
|
|
||||||
|
|
||||||
quote = Shipcloud::ShipmentQuote.create(
|
|
||||||
carrier: carrier,
|
|
||||||
service: service,
|
|
||||||
to: {
|
|
||||||
street: dst.address1,
|
|
||||||
zip_code: dst.zipcode,
|
|
||||||
city: dst.city,
|
|
||||||
country: dst.country.iso,
|
|
||||||
},
|
|
||||||
from: {
|
|
||||||
street: "Alt-Moabit",
|
|
||||||
street_no: "93",
|
|
||||||
zip_code: "10559",
|
|
||||||
city: "Berlin",
|
|
||||||
country: "DE",
|
|
||||||
},
|
|
||||||
package: {
|
|
||||||
weight: weight,
|
|
||||||
width: width,
|
|
||||||
length: length,
|
|
||||||
height: height,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
return quote.price
|
|
||||||
end
|
|
||||||
|
|
||||||
def available?(object)
|
|
||||||
# use 'compute' to determine availability
|
|
||||||
begin
|
|
||||||
price = sc_compute(object)
|
|
||||||
rescue =>
|
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
class Calculator::SysmocomScUpsStdCalculator < SysmocomScBaseCalculator
|
|
||||||
def self.description
|
|
||||||
I18n.t(:sysmocom_ups_standard)
|
|
||||||
end
|
|
||||||
|
|
||||||
def compute(object)
|
|
||||||
return sc_compute('ups', 'standard')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Calculator::SysmocomScUpsExpressCalculator < SysmocomScBaseCalculator
|
|
||||||
def self.description
|
|
||||||
I18n.t(:sysmocom_ups_express)
|
|
||||||
end
|
|
||||||
|
|
||||||
def compute(object)
|
|
||||||
return sc_compute('ups', 'one_day')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Calculator::SysmocomScUpsExpeditedCalculator < SysmocomScBaseCalculator
|
|
||||||
def self.description
|
|
||||||
I18n.t(:sysmocom_ups_expedited)
|
|
||||||
end
|
|
||||||
|
|
||||||
def compute(object)
|
|
||||||
return sc_compute('ups', 'ups_expedited')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -126,32 +126,20 @@ module Spree
|
||||||
# maximum insured value 5000 EUR
|
# maximum insured value 5000 EUR
|
||||||
end
|
end
|
||||||
|
|
||||||
def insurance_cost_DE(value)
|
# we choose pricing between 2kg and 5kg; UPS Standard via shipcloud
|
||||||
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)
|
def price_germany(value, weight)
|
||||||
if weight < 2000
|
if weight < 2000
|
||||||
price = 4.99
|
price = 5.50
|
||||||
elsif weight < 5000
|
elsif weight < 5000
|
||||||
price = 5.99
|
price = 6.50
|
||||||
elsif weight < 10000
|
elsif weight < 10000
|
||||||
price = 8.49
|
price = 7.50
|
||||||
elsif weight < 31500
|
elsif weight < 31500
|
||||||
price = 16.49
|
price = 8.50
|
||||||
else
|
else
|
||||||
price = 99999
|
price = 99999
|
||||||
end
|
end
|
||||||
return price + insurance_cost_DE(value)
|
return price
|
||||||
end
|
end
|
||||||
|
|
||||||
# We assume a 5kg package in all zones below
|
# We assume a 5kg package in all zones below
|
||||||
|
|
|
@ -21,10 +21,7 @@ module SysmocomDhl
|
||||||
app.config.spree.calculators.shipping_methods += [
|
app.config.spree.calculators.shipping_methods += [
|
||||||
# ActiveSupport magic to search a model...
|
# ActiveSupport magic to search a model...
|
||||||
Spree::Calculator::SysmocomValueCalculator,
|
Spree::Calculator::SysmocomValueCalculator,
|
||||||
Spree::Calculator::SysmocomMailValueCalculator,
|
Spree::Calculator::SysmocomMailValueCalculator
|
||||||
Spree::Calculator::SysmocomScUpsStdCalculator,
|
|
||||||
Spree::Calculator::SysmocomScUpsExpressCalculator,
|
|
||||||
Spree::Calculator::SysmocomScUpsExpeditedCalculator,
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.platform = Gem::Platform::RUBY
|
s.platform = Gem::Platform::RUBY
|
||||||
s.name = 'sysmocom_dhl'
|
s.name = 'sysmocom_dhl'
|
||||||
s.version = '2.0.0'
|
s.version = '1.2.0'
|
||||||
s.summary = 'sysmocom_dhl shipping helper'
|
s.summary = 'sysmocom_dhl shipping helper'
|
||||||
s.description = 'Deal with shipping cost, zones, insurance'
|
s.description = 'Deal with shipping cost, zones, insurance'
|
||||||
s.required_ruby_version = '>= 1.9.1'
|
s.required_ruby_version = '>= 1.9.1'
|
||||||
|
@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
||||||
s.requirements << 'none'
|
s.requirements << 'none'
|
||||||
|
|
||||||
s.add_dependency('spree_core', '>= 1.2.0')
|
s.add_dependency('spree_core', '>= 1.2.0')
|
||||||
s.add_dependency('shipcloud')
|
|
||||||
|
|
||||||
s.add_development_dependency 'capybara', '1.0.1'
|
s.add_development_dependency 'capybara', '1.0.1'
|
||||||
s.add_development_dependency 'factory_girl', '~> 2.6.4'
|
s.add_development_dependency 'factory_girl', '~> 2.6.4'
|
||||||
|
|
Loading…
Reference in New Issue