Created
October 23, 2014 21:54
-
-
Save JDutil/8c6fdca65420b273855b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 module Spree | |
ItemAdjustments.class_eval do | |
2 | |
3 # Picks one (and only one) promotion to be eligible for this order | |
4 # This promotion provides the most discount, and if two promotions | |
5 # have the same amount, then it will pick the latest one. | |
6 def choose_best_promotion_adjustment | |
7 raise "#{adjustment}" | |
8 if best_promotion_adjustment | |
9 other_promotions = self.adjustments.promotion.where.not(id: best_promotion_adjustment.id) | |
10 #other_promotions.update_all(:eligible => false) | |
11 end | |
12 end | |
13 | |
14 def best_promotion_adjustment | |
15 @best_promotion_adjustment ||= adjustments.promotion.eligible.reorder("amount ASC, created_at DESC, id DESC") | |
16 end | |
end | |
17 end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment