conditions completed
This commit is contained in:
parent
7e37b52e20
commit
b72dfdabf8
2 changed files with 23 additions and 47 deletions
|
|
@ -10,9 +10,10 @@ class TicketPurchasesController < ApplicationController
|
||||||
current_user.ticket_purchases.by_conference(@conference).unpaid.destroy_all
|
current_user.ticket_purchases.by_conference(@conference).unpaid.destroy_all
|
||||||
|
|
||||||
# Create a ticket purchase which can be paid or unpaid
|
# Create a ticket purchase which can be paid or unpaid
|
||||||
|
count_registration_tickets_before = current_user.count_registration_tickets(@conference)
|
||||||
message = TicketPurchase.purchase(@conference, current_user, params[:tickets].try(:first))
|
message = TicketPurchase.purchase(@conference, current_user, params[:tickets].try(:first))
|
||||||
# The new ticket_purchase has been added to the database. current_user.ticket_purchases contains the new one.
|
# The new ticket_purchase has been added to the database. current_user.ticket_purchases contains the new one.
|
||||||
current_ticket_purchase = ?
|
count_registration_tickets_after = current_user.count_registration_tickets(@conference)
|
||||||
|
|
||||||
# Failed to create ticket purchase
|
# Failed to create ticket purchase
|
||||||
if !message.blank?
|
if !message.blank?
|
||||||
|
|
@ -28,49 +29,25 @@ class TicketPurchasesController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: User already paid for a registration ticket and ticket purchase contains one
|
# Current user already paid for a registration ticket and the current ticket purchase contains one
|
||||||
# BUG: When the ticket is free, user will see the notice after they click `Continue`
|
if count_registration_tickets_before == 1 && count_registration_tickets_after > 1
|
||||||
|
redirect_to conference_physical_tickets_path,
|
||||||
# this works? maybe
|
notice: 'You already have tickets for the conference.'
|
||||||
|
return
|
||||||
# TODO: Need to check
|
|
||||||
|
|
||||||
# user has a registration ticket
|
|
||||||
# current_user.tickets.for_registration(@conference).present?
|
|
||||||
|
|
||||||
# current ticket purchase
|
|
||||||
if current_user.ticket_purchases.by_conference(@conference).paid.any?
|
|
||||||
&& current_user.has_registration_ticket_for?(@conference) == true
|
|
||||||
end
|
|
||||||
for ticket_purchase in current_user.ticket_purchases.by_conference(@conference)
|
|
||||||
if ticket_purchase.paid?
|
|
||||||
for physical_ticket in ticket_purchase.physical_tickets
|
|
||||||
if physical_ticket.ticket.registration_ticket?
|
|
||||||
redirect_to conference_physical_tickets_path,
|
|
||||||
notice: 'You already have tickets for the conference.'
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: User wants to purchase a non-registration ticket but does not have a registration ticket but conference requires one
|
# Conference requires a registration ticket but the current user wants to purchase a non-registration ticket
|
||||||
# BUG: When the user only purchases a non-registration ticket,
|
# and does not have a registration ticket
|
||||||
if @conference.registration_ticket_required?
|
if @conference.registration_ticket_required? && count_registration_tickets_after == 0
|
||||||
&& current_user.has_registration_ticket_for?(@conference) == false
|
redirect_to conference_tickets_path(@conference.short_title),
|
||||||
redirect_to conference_tickets_path(@conference.short_title),
|
error: 'Please get at least one registration ticket to continue.'
|
||||||
error: 'Please get at least one registration ticket to continue.'
|
return
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Need to check if the current user didn't have a registration ticket and is purchasing one
|
# Current user didn't have a registration ticket and is purchasing one
|
||||||
if current_user.tickets.for_registration(@conference).nil?
|
if count_registration_tickets_before == 0 && count_registration_tickets_after == 1
|
||||||
if current_user.has_registration_ticket_for?(@conference) == true
|
redirect_to new_conference_conference_registration_path(@conference.short_title)
|
||||||
redirect_to new_conference_conference_registration_path(@conference.short_title)
|
|
||||||
else
|
|
||||||
redirect_to conference_physical_tickets_path
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
redirect_to conference_physical_tickets_path
|
redirect_to conference_physical_tickets_path
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -346,18 +346,17 @@ class User < ApplicationRecord
|
||||||
events.where(program_id: conference.program.id, 'event_users.event_role': 'volunteer')
|
events.where(program_id: conference.program.id, 'event_users.event_role': 'volunteer')
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_registration_ticket_for?(conference)
|
def count_registration_tickets(conference)
|
||||||
seen_registration = false
|
count = 0
|
||||||
for ticket_purchase in current_user.ticket_purchases.by_conference(@conference)
|
for ticket_purchase in current_user.ticket_purchases.by_conference(@conference)
|
||||||
for physical_ticket in ticket_purchase.physical_tickets
|
for physical_ticket in ticket_purchase.physical_tickets
|
||||||
if physical_ticket.ticket.registration_ticket
|
if physical_ticket.ticket.registration_ticket
|
||||||
seen_registration = true
|
count += 1
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return seen_registration
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.empty?
|
def self.empty?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue