Sha256: 7b63d190a018821b2f7098b1fb06edfb9accf35514af481a2c1015d8f4754477
Contents?: true
Size: 681 Bytes
Versions: 34
Compression:
Stored size: 681 Bytes
Contents
class PercentageOffTicketsDiscountType < DiscountType discount_type :percentage_off_tickets def apply_discount_to_cart ensure_percentage_exists eligible_tickets.each do |ticket| ticket.update_column(:discount_id, @discount.id) ticket.update_attributes(:cart_price => ticket.price - (ticket.price * @properties[:percentage])) end end def validate @discount.errors[:base] = "Amount must be filled in." unless @properties[:percentage].present? end def to_s "#{@properties[:percentage] * 100.00}% off each ticket" end private def ensure_percentage_exists raise "Percentage missing!" if @properties[:percentage].blank? end end
Version data entries
34 entries across 34 versions & 1 rubygems