From 8a6301c8a9ebc8a04c8c44fe8bc21003f8932c16 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 17 Apr 2013 13:56:51 +0200 Subject: [PATCH] calculator: Another attempt to work with the Shipment Resolve the address from the shipment.address which might but I assume is not different to the order.address. --- .../calculator/sysmocom_value_calculator.rb | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/spree/calculator/sysmocom_value_calculator.rb b/app/models/spree/calculator/sysmocom_value_calculator.rb index 596ac5c..bc54fb8 100644 --- a/app/models/spree/calculator/sysmocom_value_calculator.rb +++ b/app/models/spree/calculator/sysmocom_value_calculator.rb @@ -153,18 +153,26 @@ ZONE3 = { item_total end - def compute(order) + 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(order) + shipping_value = total_value_no_tax(object) + iso_code = extract_iso_code(object) # Go through the zones by name... - if order.ship_address.country.iso == 'DE' + if iso_code == 'DE' return price_germany(shipping_value) - elsif ZONE1.has_key?(order.ship_address.country.iso) + elsif ZONE1.has_key?(iso_code) return price_package_zone1(shipping_value) - elsif ZONE2.has_key?(order.ship_address.country.iso) + elsif ZONE2.has_key?(iso_code) return price_package_zone2(shipping_value) - elsif ZONE3.has_key?(order.ship_address.country.iso) + elsif ZONE3.has_key?(iso_code) return price_package_zone3(shipping_value) else return price_package_zone4(shipping_value)