Class: Cart
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cart
- Includes:
- ActiveRecord::Transitions
- Defined in:
- app/models/carts/cart.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#special_instructions ⇒ Object
Returns the value of attribute special_instructions.
Instance Method Summary collapse
- #<<(tkts) ⇒ Object
- #as_json(options = {}) ⇒ Object
- #can_hold?(ticket) ⇒ Boolean
- #checkout_class ⇒ Object
- #clear! ⇒ Object
- #clear_donations ⇒ Object
- #clear_tickets ⇒ Object
- #completed? ⇒ Boolean
- #discount_amount ⇒ Object
- #expire_ticket(ticket) ⇒ Object
- #fee_in_cents ⇒ Object
- #finish ⇒ Object
- #generate_donations ⇒ Object
- #items ⇒ Object
- #items_subject_to_fee ⇒ Object
- #organizations ⇒ Object
- #organizations_from_donations ⇒ Object
- #organizations_from_tickets ⇒ Object
- #pay_with(payment, options = {}) ⇒ Object
- #release_tickets ⇒ Object
- #reseller_is?(reseller) ⇒ Boolean
- #reset_prices_on_tickets ⇒ Object
- #set_timeout(ticket) ⇒ Object
- #subtotal ⇒ Object
- #total ⇒ Object
- #total_before_discount ⇒ Object
- #unfinished? ⇒ Boolean
Instance Attribute Details
#special_instructions ⇒ Object
Returns the value of attribute special_instructions.
7 8 9 |
# File 'app/models/carts/cart.rb', line 7 def special_instructions @special_instructions end |
Instance Method Details
#<<(tkts) ⇒ Object
79 80 81 |
# File 'app/models/carts/cart.rb', line 79 def <<(tkts) self.tickets << tkts end |
#as_json(options = {}) ⇒ Object
35 36 37 |
# File 'app/models/carts/cart.rb', line 35 def as_json( = {}) super({ :methods => [ 'tickets', 'donations' ]}.merge()) end |
#can_hold?(ticket) ⇒ Boolean
144 145 146 |
# File 'app/models/carts/cart.rb', line 144 def can_hold?(ticket) true end |
#checkout_class ⇒ Object
25 26 27 |
# File 'app/models/carts/cart.rb', line 25 def checkout_class Checkout end |
#clear! ⇒ Object
29 30 31 32 33 |
# File 'app/models/carts/cart.rb', line 29 def clear! reset_prices_on_tickets clear_tickets clear_donations end |
#clear_donations ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'app/models/carts/cart.rb', line 69 def clear_donations temp = [] #This won't work if there is more than 1 FAFS donation on the order donations.each do |donation| temp = donations.delete(donations) end temp end |
#clear_tickets ⇒ Object
39 40 41 42 |
# File 'app/models/carts/cart.rb', line 39 def clear_tickets release_tickets self.tickets = [] end |
#completed? ⇒ Boolean
103 104 105 |
# File 'app/models/carts/cart.rb', line 103 def completed? approved? end |
#discount_amount ⇒ Object
95 96 97 |
# File 'app/models/carts/cart.rb', line 95 def discount_amount total_before_discount - total end |
#expire_ticket(ticket) ⇒ Object
56 57 58 59 |
# File 'app/models/carts/cart.rb', line 56 def expire_ticket(ticket) ticket.reset_price! tickets.delete(ticket) end |
#fee_in_cents ⇒ Object
65 66 67 |
# File 'app/models/carts/cart.rb', line 65 def fee_in_cents items_subject_to_fee.size * (ARTFULLY_CONFIG[:ticket_fee] || 0) end |
#finish ⇒ Object
119 120 |
# File 'app/models/carts/cart.rb', line 119 def finish end |
#generate_donations ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'app/models/carts/cart.rb', line 122 def generate_donations organizations_from_tickets.collect do |organization| if organization.can?(:receive, Donation) donation = Donation.new donation.organization = organization donation end end.compact end |
#items ⇒ Object
21 22 23 |
# File 'app/models/carts/cart.rb', line 21 def items self.tickets + self.donations end |
#items_subject_to_fee ⇒ Object
61 62 63 |
# File 'app/models/carts/cart.rb', line 61 def items_subject_to_fee self.tickets.reject{|t| t.price == 0} end |
#organizations ⇒ Object
132 133 134 |
# File 'app/models/carts/cart.rb', line 132 def organizations (organizations_from_donations + organizations_from_tickets).uniq end |
#organizations_from_donations ⇒ Object
136 137 138 |
# File 'app/models/carts/cart.rb', line 136 def organizations_from_donations Organization.find(donations.collect(&:organization_id)) end |
#organizations_from_tickets ⇒ Object
140 141 142 |
# File 'app/models/carts/cart.rb', line 140 def organizations_from_tickets Organization.find(tickets.collect(&:organization_id)) end |
#pay_with(payment, options = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/carts/cart.rb', line 107 def pay_with(payment, = {}) @payment = payment #TODO: Move the requires_authorization? check into the payments classes. Cart shouldn't care if payment. [:service_fee] = fee_in_cents (payment, ) else approve! end end |
#release_tickets ⇒ Object
44 45 46 |
# File 'app/models/carts/cart.rb', line 44 def release_tickets tickets.each { |ticket| ticket.remove_from_cart } end |
#reseller_is?(reseller) ⇒ Boolean
148 149 150 |
# File 'app/models/carts/cart.rb', line 148 def reseller_is?(reseller) reseller == nil end |
#reset_prices_on_tickets ⇒ Object
152 153 154 155 156 |
# File 'app/models/carts/cart.rb', line 152 def reset_prices_on_tickets transaction do tickets.each {|ticket| ticket.reset_price! } end end |
#set_timeout(ticket) ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/models/carts/cart.rb', line 48 def set_timeout(ticket) save if new_record? if Delayed::Worker.delay_jobs self.delay(:run_at => Time.now + 10.minutes).expire_ticket(ticket) end end |
#subtotal ⇒ Object
83 84 85 |
# File 'app/models/carts/cart.rb', line 83 def subtotal items.sum(&:price) end |
#total ⇒ Object
91 92 93 |
# File 'app/models/carts/cart.rb', line 91 def total items.sum(&:cart_price) + fee_in_cents end |
#total_before_discount ⇒ Object
87 88 89 |
# File 'app/models/carts/cart.rb', line 87 def total_before_discount items.sum(&:price) + fee_in_cents end |
#unfinished? ⇒ Boolean
99 100 101 |
# File 'app/models/carts/cart.rb', line 99 def unfinished? started? or rejected? end |