Class: BuyOneGetOneFreeDiscountType

Inherits:
DiscountType show all
Defined in:
app/models/discounts/buy_one_get_one_free_discount_type.rb

Instance Attribute Summary

Attributes inherited from DiscountType

#properties

Instance Method Summary collapse

Methods inherited from DiscountType

discount_type, #eligible_tickets, #initialize, #tickets, types

Constructor Details

This class inherits a constructor from DiscountType

Instance Method Details

#apply_discount_to_cartObject



4
5
6
7
8
9
10
11
# File 'app/models/discounts/buy_one_get_one_free_discount_type.rb', line 4

def apply_discount_to_cart
  eligible_tickets.each do |ticket|
    ticket.update_column(:discount_id, @discount.id) unless ticket == eligible_tickets.last && eligible_tickets.count.odd?
  end
  eligible_tickets.values_at(* eligible_tickets.each_index.select {|i| i.odd?}).each do |ticket|
    ticket.update_column(:cart_price, 0)
  end
end

#to_sObject



17
18
19
# File 'app/models/discounts/buy_one_get_one_free_discount_type.rb', line 17

def to_s
  "Buy one, get one free"
end

#validateObject



13
14
15
# File 'app/models/discounts/buy_one_get_one_free_discount_type.rb', line 13

def validate
  # Nothing to do here.
end