Module: SolidusFriendlyPromotions::OrderDecorator
- Defined in:
- app/decorators/models/solidus_friendly_promotions/order_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #apply_shipping_promotions ⇒ Object
- #discountable_item_total ⇒ Object
-
#discountable_line_items ⇒ Object
This helper method excludes line items that are managed by an order benefit for the benefit of calculators and benefits that discount normal line items.
- #ensure_promotions_eligible ⇒ Object
- #free_from_order_benefit?(line_item, _options) ⇒ Boolean
- #reset_current_discounts ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
5 6 7 8 9 10 11 |
# File 'app/decorators/models/solidus_friendly_promotions/order_decorator.rb', line 5 def self.prepended(base) base.has_many :friendly_order_promotions, class_name: "SolidusFriendlyPromotions::OrderPromotion", dependent: :destroy, inverse_of: :order base.has_many :friendly_promotions, through: :friendly_order_promotions, source: :promotion end |
Instance Method Details
#apply_shipping_promotions ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/decorators/models/solidus_friendly_promotions/order_decorator.rb', line 39 def apply_shipping_promotions if Spree::Config.promotion_adjuster_class <= SolidusFriendlyPromotions::FriendlyPromotionAdjuster recalculate else super end end |
#discountable_item_total ⇒ Object
23 24 25 |
# File 'app/decorators/models/solidus_friendly_promotions/order_decorator.rb', line 23 def discountable_item_total line_items.sum(&:discountable_amount) end |
#discountable_line_items ⇒ Object
This helper method excludes line items that are managed by an order benefit for the benefit of calculators and benefits that discount normal line items. Line items that are managed by an order benefits handle their discounts themselves.
35 36 37 |
# File 'app/decorators/models/solidus_friendly_promotions/order_decorator.rb', line 35 def discountable_line_items line_items.reject(&:managed_by_order_benefit) end |
#ensure_promotions_eligible ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/decorators/models/solidus_friendly_promotions/order_decorator.rb', line 13 def ensure_promotions_eligible Spree::Config.promotion_adjuster_class.new(self).call if promo_total_changed? restart_checkout_flow recalculate errors.add(:base, I18n.t("solidus_friendly_promotions.promotion_total_changed_before_complete")) end errors.empty? end |
#free_from_order_benefit?(line_item, _options) ⇒ Boolean
47 48 49 |
# File 'app/decorators/models/solidus_friendly_promotions/order_decorator.rb', line 47 def free_from_order_benefit?(line_item, ) !line_item.managed_by_order_benefit end |
#reset_current_discounts ⇒ Object
27 28 29 30 |
# File 'app/decorators/models/solidus_friendly_promotions/order_decorator.rb', line 27 def reset_current_discounts line_items.each(&:reset_current_discounts) shipments.each(&:reset_current_discounts) end |