Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Correct issue with per item calculator and no matching products

Relates to #1596
  • Loading branch information...
commit fd6e97a5607b4a3ee9dc93aa427ff6a0140deccb 1 parent e2395da
@radar radar authored
View
6 core/app/models/spree/calculator/per_item.rb
@@ -11,7 +11,11 @@ def self.description
def compute(object=nil)
return 0 if object.nil?
self.preferred_amount * object.line_items.reduce(0) do |sum, value|
- value_to_add = matching_products.include?(value.product) ? value.quantity : 0
+ if matching_products && matching_products.include?(value.product)
+ value_to_add = value.quantity
+ else
+ value_to_add = 0
+ end
sum + value_to_add
end
end
View
12 core/spec/models/calculator/per_item_spec.rb
@@ -2,9 +2,17 @@
describe Spree::Calculator::PerItem do
# Like an order object, but not quite...
- let!(:line_items) { [double("LineItem", :quantity => 5)] * 3 }
+ let!(:product) { double("Product") }
+ let!(:line_items) { [double("LineItem", :quantity => 5, :product => product)] * 3 }
let!(:object) { double("Order", :line_items => line_items) }
- let!(:calculator) { Spree::Calculator::PerItem.new(:preferred_amount => 10) }
+ let!(:calculable) { double("Calculable", :promotion => promotion) }
+ let!(:promotion) { double("Promotion", :rules => [double("Rule", :products => [product])]) }
+
+ let!(:calculator) do
+ calculator = Spree::Calculator::PerItem.new(:preferred_amount => 10)
+ calculator.stub(:calculable => calculable)
+ calculator
+ end
# regression test for #1414
it "correctly calculates per item shipping" do
Please sign in to comment.
Something went wrong with that request. Please try again.