jurgis/spree-additional-calculators — Issue #2: help
Author: greengrass
Created: 2012-01-10 08:43:21+00:00
State: open

hi I have been stuck for a number of days now, I need a calculator that works, below I have pasted the code I have so far, this works fine with one product with any number of quantities in the basket, however as soon as I add another product the conditional statements re run and the whole process starts again, I need any number of products in the basket and for the calculator to work as it should below, am so desperate now, I have no where to turn, can you please help, please!!!!!!!!!

class Calculator::Standard< Calculator
preference :amount, :decimal, :default => 0

def self.description
I18n.t("standard")
end

def self.register
super
Coupon.register_calculator(self)
ShippingMethod.register_calculator(self)
ShippingRate.register_calculator(self)
end

def compute(line_items)
return if line_items.nil?
item_total = line_items.inject(0) {|amount, li| amount + li.total }
items_count = line_items.inject(0) {|count, line_item| count + line_item.quantity }
sum = preferred_amount * items_count

if (item_total) >=100 : (return 0)

elsif (items_count) >=4 : (return 16)

end
return items_count
end
end