Class: PercentageOffTicketsDiscountType
- Inherits:
-
DiscountType
show all
- Defined in:
- app/models/discounts/percentage_off_tickets_discount_type.rb
Instance Attribute Summary
Attributes inherited from DiscountType
#properties
Instance Method Summary
collapse
discount_type, #eligible_tickets, #initialize, #tickets, types
Constructor Details
This class inherits a constructor from DiscountType
Instance Method Details
#apply_discount_to_cart ⇒ Object
4
5
6
7
8
9
10
|
# File 'app/models/discounts/percentage_off_tickets_discount_type.rb', line 4
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
|
#to_s ⇒ Object
16
17
18
|
# File 'app/models/discounts/percentage_off_tickets_discount_type.rb', line 16
def to_s
"#{@properties[:percentage] * 100.00}% off each ticket"
end
|
#validate ⇒ Object
12
13
14
|
# File 'app/models/discounts/percentage_off_tickets_discount_type.rb', line 12
def validate
@discount.errors[:base] = "Amount must be filled in." unless @properties[:percentage].present?
end
|