Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed product matching and updated readme for promotions #25

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Next Next commit
products with variants now related properly
imme5150 committed Mar 1, 2012
commit 90c837f6667fecb82ebc765128f1897deae633ff
6 changes: 3 additions & 3 deletions app/models/spree/calculator/related_product_discount.rb
Original file line number Diff line number Diff line change
@@ -17,11 +17,11 @@ def compute(object)
return unless eligible?(order)
total = order.line_items.inject(0) do |total, line_item|
relations = Spree::Relation.find(:all, :conditions => ["discount_amount <> 0.0 AND relatable_type = ? AND relatable_id = ?", "Spree::Product", line_item.variant.product.id])
discount_applies_to = relations.map {|rel| rel.related_to.master }
discount_applies_to = relations.map {|rel| rel.related_to }

order.line_items.each do |li|
if discount_applies_to.include? li.variant
discount = relations.detect {|rel| rel.related_to.master == li.variant}.discount_amount
if discount_applies_to.include? li.product
discount = relations.detect {|rel| rel.related_to == li.product}.discount_amount

total += if li.quantity < line_item.quantity
(discount * li.quantity)