Class: Spree::PromotionChooser
- Inherits:
-
Object
- Object
- Spree::PromotionChooser
- Defined in:
- app/models/spree/promotion_chooser.rb
Instance Method Summary collapse
-
#initialize(adjustments) ⇒ PromotionChooser
constructor
A new instance of PromotionChooser.
-
#update ⇒ BigDecimal
Picks the best promotion from this set of adjustments, all others are marked as ineligible.
Constructor Details
#initialize(adjustments) ⇒ PromotionChooser
Returns a new instance of PromotionChooser.
3 4 5 |
# File 'app/models/spree/promotion_chooser.rb', line 3 def initialize(adjustments) @adjustments = adjustments end |
Instance Method Details
#update ⇒ BigDecimal
Picks the best promotion from this set of adjustments, all others are marked as ineligible.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/spree/promotion_chooser.rb', line 11 def update if best_promotion_adjustment @adjustments.select(&:eligible?).each do |adjustment| next if adjustment == best_promotion_adjustment adjustment.update_columns(eligible: false) end best_promotion_adjustment.amount else BigDecimal.new('0') end end |