From 698ae27da18782b09ea05d7c115d521a60785ae0 Mon Sep 17 00:00:00 2001 From: Massimiliano Tavanti Date: Sun, 10 Nov 2013 15:33:16 +0100 Subject: [PATCH] fix nil cost_price + operator bug --- app/models/spree/line_item_decorator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index ace9380..a945146 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -34,7 +34,8 @@ def options_text end def cost_price - variant.cost_price + ad_hoc_option_values.map(&:cost_price).inject(0, :+) + #due to the fact that cost_price can be nil we must convert it into bigdecimal (to_f will make nil->0 without losing precision in case of value) + variant.cost_price.to_f.to_d + ad_hoc_option_values.map(&:cost_price).inject(0, :+) end def cost_money