Sha256: 21071da64cdfae8f43ecba177c67419c2f3d726dd55e3ad2c6ba3c883e1d4b72

Contents?: true

Size: 658 Bytes

Versions: 31

Compression:

Stored size: 658 Bytes

Contents

class BuyOneGetOneFreeDiscountType < DiscountType
  discount_type :buy_one_get_one_free

  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
    every_other_ticket.each do |ticket|
      ticket.update_column(:cart_price, 0)
    end
    FeeCalculator.apply(FeeStrategy.new).to(@discount.cart)
  end

  def every_other_ticket
    eligible_tickets.values_at(* eligible_tickets.each_index.select {|i| i.odd?})
  end

  def validate
    # Nothing to do here.
  end

  def to_s
    "Buy one, get one free"
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
artfully_ose-1.3.0.pre3 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.3.0.pre2 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.3.0.pre1 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.beta.1 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.alpha.2 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.alpha.1 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.27 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.26 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.24 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.23 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.21 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.20 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.19 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.18 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.17 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.16 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.15 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.12 app/models/discounts/buy_one_get_one_free_discount_type.rb
artfully_ose-1.2.0.pre.11 app/models/discounts/buy_one_get_one_free_discount_type.rb