Class: SolidusFriendlyPromotions::Benefits::CreateDiscountedItem

Inherits:
SolidusFriendlyPromotions::Benefit show all
Includes:
OrderBenefit
Defined in:
app/models/solidus_friendly_promotions/benefits/create_discounted_item.rb

Instance Method Summary collapse

Methods included from OrderBenefit

#can_discount?, #level

Methods inherited from SolidusFriendlyPromotions::Benefit

#adjustment_label, #applicable_line_items, #available_calculators, #available_conditions, #can_discount?, #compute_amount, #discount, #eligible_by_applicable_conditions?, #level, #possible_conditions, #preload_relations, #to_partial_path

Instance Method Details

#perform(order) ⇒ Object



11
12
13
14
15
# File 'app/models/solidus_friendly_promotions/benefits/create_discounted_item.rb', line 11

def perform(order)
  line_item = find_item(order) || create_item(order)
  set_quantity(line_item, determine_item_quantity(order))
  line_item.current_discounts << discount(line_item)
end

#remove_from(order) ⇒ Object



17
18
19
20
# File 'app/models/solidus_friendly_promotions/benefits/create_discounted_item.rb', line 17

def remove_from(order)
  line_item = find_item(order)
  order.line_items.destroy(line_item)
end