Module: Ticket::Locker::ClassMethods

Defined in:
app/models/ticket/locker.rb

Instance Method Summary collapse

Instance Method Details

#lock(tickets, ticket_type, cart) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/ticket/locker.rb', line 5

def lock(tickets, ticket_type, cart)
  tickets = Array.wrap(tickets)

  #
  # TODO: blow up if this ticket_type does not apply to this show
  #
  Rails.logger.debug(tickets.inspect)
  Ticket.where(:id => tickets).update_all({ :cart_id        => cart.id, 
                                            :ticket_type_id => ticket_type.id, 
                                            :cart_price     => ticket_type.price
                                            })
  tickets = Ticket.includes(:ticket_type).where(:id => tickets)
  Rails.logger.debug(tickets.inspect)
  cart << tickets
  ExpireTicketJob.enqueue(tickets.collect(&:id), cart.id)
  tickets
end

#unlock(tickets, cart) ⇒ Object

We pass cart so that we can ensure we’re expiring the right transaction. The ticket could have moved carts since the job was queued.

If we come along and expire it, the patron will be bitter.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/ticket/locker.rb', line 29

def unlock(tickets, cart)
  
  Ticket.where(:id => tickets)
        .where(:cart_id => cart)
        .uncommitted
        .update_all({ :cart_id        => nil, 
                      :ticket_type_id => nil,
                      :pass_id        => nil,  
                      :cart_price     => nil,
                      :sold_price     => nil,
                      :service_fee    => 0,
                      :discount_id    => nil
                    })
end