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.
5 6 7 |
# File 'app/models/spree/promotion_chooser.rb', line 5 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.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/spree/promotion_chooser.rb', line 13 def update if best_promotion_adjustment @adjustments.select(&:eligible?).each do |adjustment| next if adjustment == best_promotion_adjustment adjustment.update_columns(eligible: false, updated_at: Time.current) end best_promotion_adjustment.amount else BigDecimal('0') end end |