65 lines
1.7 KiB
Ruby
Executable File
65 lines
1.7 KiB
Ruby
Executable File
class PartiesController < ApplicationController
|
|
# Display all events
|
|
def index
|
|
@parties = Party.includes(:user).upcoming.page(params[:page]).per(1)
|
|
# @parties = Party.page(params[:page]).per(12)
|
|
end
|
|
|
|
# Display desired event
|
|
def show
|
|
@party = Party.find(params[:id])
|
|
end
|
|
|
|
# Handle checkout process
|
|
def checkout
|
|
@party = Party.find(params[:id])
|
|
cart_data = JSON.parse(params[:cart] || "{}")
|
|
|
|
if cart_data.empty?
|
|
redirect_to party_path(@party), alert: "Please select at least one ticket"
|
|
return
|
|
end
|
|
|
|
# Create order items from cart
|
|
order_items = []
|
|
total_amount = 0
|
|
|
|
cart_data.each do |ticket_type_id, item|
|
|
ticket_type = @party.ticket_types.find_by(id: ticket_type_id)
|
|
next unless ticket_type
|
|
|
|
quantity = item["quantity"].to_i
|
|
next if quantity <= 0
|
|
|
|
# Check availability
|
|
available = ticket_type.quantity - ticket_type.tickets.count
|
|
if quantity > available
|
|
redirect_to party_path(@party), alert: "Not enough tickets available for #{ticket_type.name}"
|
|
return
|
|
end
|
|
|
|
order_items << {
|
|
ticket_type: ticket_type,
|
|
quantity: quantity,
|
|
price_cents: ticket_type.price_cents
|
|
}
|
|
|
|
total_amount += ticket_type.price_cents * quantity
|
|
end
|
|
|
|
if order_items.empty?
|
|
redirect_to party_path(@party), alert: "Invalid order"
|
|
return
|
|
end
|
|
|
|
# Here you would typically:
|
|
# 1. Create an Order record
|
|
# 2. Create Ticket records for each item
|
|
# 3. Redirect to payment processing
|
|
|
|
# For now, we'll just redirect with a success message
|
|
# In a real app, you'd redirect to a payment page
|
|
redirect_to party_path(@party), notice: "Order created successfully! Proceeding to payment..."
|
|
end
|
|
end
|