Class: SalesController
- Inherits:
-
ArtfullyOseController
- Object
- ActionController::Base
- ArtfullyOseController
- SalesController
- Defined in:
- app/controllers/sales_controller.rb
Instance Method Summary collapse
- #checking_out? ⇒ Boolean
-
#create ⇒ Object
This needs a significant refactor.
- #door_list_rows ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
Instance Method Details
#checking_out? ⇒ Boolean
44 45 46 |
# File 'app/controllers/sales_controller.rb', line 44 def checking_out? !params[:commit].blank? end |
#create ⇒ Object
This needs a significant refactor. There is no way to maintain the sale object across requests. Because of this the number of locked tickets proliferates.
Refactor this to maintain the cart across requests and clear the cart on successful sale
In the meantime, BoxOffice::Cart has been jenked to just not lock tickets.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/sales_controller.rb', line 25 def create @sale = Sale.new(@show, @show.chart.sections.box_office, params[:quantities]) if checking_out? if @sale.sell(payment) @sale. = "Sold #{self.class.helpers.pluralize(@sale.tickets.length, 'ticket')}. Order total was #{self.class.helpers.number_as_cents @sale.cart.total}" end end unless @sale.errors.empty? @sale.error = "#{@sale.errors..to_sentence.capitalize}." end render :json => @sale.as_json .merge(:total => @sale.cart.total) .merge(:tickets_remaining => tickets_remaining) .merge(:door_list_rows => door_list_rows), :status => 200 end |
#door_list_rows ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/sales_controller.rb', line 48 def door_list_rows door_list_rows = [] puts @sale.tickets.inspect @sale.tickets.each_with_index do |ticket, i| ticket.reload if ticket.sold? || ticket.comped? door_list_rows[i] = {} door_list_rows[i]['first_name'] = @sale.buyer.first_name door_list_rows[i]['last_name'] = @sale.buyer.last_name door_list_rows[i]['email'] = @sale.buyer.email door_list_rows[i]['section'] = ticket.section.name door_list_rows[i]['payment_method'] = ticket.sold_item.order.payment_method door_list_rows[i]['price'] = ticket.sold_price end end door_list_rows end |
#new ⇒ Object
9 10 11 12 13 14 |
# File 'app/controllers/sales_controller.rb', line 9 def new @person = Person.new @sale = Sale.new(@show, @show.chart.sections.box_office) @tickets_remaining = tickets_remaining setup_defaults end |
#show ⇒ Object
5 6 7 |
# File 'app/controllers/sales_controller.rb', line 5 def show redirect_to new_event_show_sales_path(@event, @show) end |