feat(show parties): prepare to use ticket cart components

This commit is contained in:
kbe
2025-08-27 02:31:20 +02:00
parent 1806c875b5
commit 7c7db939a2
8 changed files with 398 additions and 85 deletions

View File

@@ -9,4 +9,56 @@ class PartiesController < ApplicationController
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