Module: SolidusPromotions::OrderPatch

Includes:
selfself::ClassMethods
Defined in:
app/patches/models/solidus_promotions/order_patch.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



11
12
13
14
15
16
17
# File 'app/patches/models/solidus_promotions/order_patch.rb', line 11

def self.prepended(base)
  base.has_many :solidus_order_promotions,
    class_name: "SolidusPromotions::OrderPromotion",
    dependent: :destroy,
    inverse_of: :order
  base.has_many :solidus_promotions, through: :solidus_order_promotions, source: :promotion
end

Instance Method Details

#coupon_code=(code) ⇒ Object



39
40
41
42
43
44
45
# File 'app/patches/models/solidus_promotions/order_patch.rb', line 39

def coupon_code=(code)
  @coupon_code = begin
    SolidusPromotions.config.coupon_code_normalizer_class.call(code)
  rescue
    nil
  end
end

#discountable_item_totalObject



19
20
21
# File 'app/patches/models/solidus_promotions/order_patch.rb', line 19

def discountable_item_total
  line_items.sum(&:discountable_amount)
end

#discountable_line_itemsObject

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.



31
32
33
# File 'app/patches/models/solidus_promotions/order_patch.rb', line 31

def discountable_line_items
  line_items.reject(&:managed_by_order_benefit)
end

#free_from_order_benefit?(line_item, _options) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/patches/models/solidus_promotions/order_patch.rb', line 35

def free_from_order_benefit?(line_item, _options)
  !line_item.managed_by_order_benefit
end

#reset_current_discountsObject



23
24
25
26
# File 'app/patches/models/solidus_promotions/order_patch.rb', line 23

def reset_current_discounts
  line_items.each(&:reset_current_discounts)
  shipments.each(&:reset_current_discounts)
end