Class: ExchangesController

Inherits:
ArtfullyOseController show all
Defined in:
app/controllers/exchanges_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/exchanges_controller.rb', line 28

def create
  order = Order.find(params[:order_id])
  items = params[:items].collect { |item_id| Item.find(item_id) }
  ticket_type = TicketType.find(params[:ticket_type_id])
  tickets = ticket_type.available_tickets(items.count)
  logger.debug("Beginning exchange")
  @exchange = Exchange.new(order, items, tickets, ticket_type, send_email_confirmation?)

  if tickets.nil?
    flash[:error] = "Please select tickets to exchange."
    redirect_to :back
  elsif tickets.size != items.size
    flash[:error] = "There were not enough tickets available for this show. (#{items.size} needed, #{tickets.size} available.)"
    redirect_to :back
  elsif @exchange.valid?
    logger.debug("Submitting exchange")
    @exchange.submit
    redirect_to order_url(order), :notice => "Successfully exchanged #{self.class.helpers.pluralize(items.length, 'ticket')}"
  else
    flash[:error] = "Unable to process exchange."
    Rails.logger.error("Unable to process exchange: #{@exchange.errors.full_messages.to_sentence}")
    redirect_to :back
  end
end

#newObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/exchanges_controller.rb', line 2

def new
  @items = Item.includes(:product => [:show => [:event => :venue]]).where(:id => params[:items])
  @order = @items.first.order
  @person = @order.person

  if @items.all?(&:exchangeable?)
    @events = current_organization.events.sort

    unless params[:event_id].blank?
      @event = Event.find(params[:event_id])
      @shows = @event.upcoming_shows(:all)
      unless params[:show_id].blank? || @event.blank?
        @show = Show.includes(:event => :venue, :chart => [:sections => :ticket_types]).find(params[:show_id])
        unless params[:ticket_type_id].blank? || @show.blank?
          @ticket_type = TicketType.find(params[:ticket_type_id])
          @num_available_tickets = @ticket_type.available
          @free_upgrade = @ticket_type.price > @items.first.price
        end
      end
    end
  else
    flash[:error] = "Some of the selected items are not exchangable."
    redirect_to order_url(params[:order_id])
  end
end

#send_email_confirmation?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/controllers/exchanges_controller.rb', line 53

def send_email_confirmation?
  params[:send_email_confirmation] == "1"
end