feat: Add promotion code functionality to ticket orders
This commit is contained in:
@@ -126,6 +126,20 @@ class OrdersController < ApplicationController
|
||||
@total_amount = @order.total_amount_cents
|
||||
@expiring_soon = @order.expiring_soon?
|
||||
|
||||
# Handle promotion code application
|
||||
if params[:promotion_code].present?
|
||||
promotion_code = PromotionCode.valid.find_by(code: params[:promotion_code].upcase)
|
||||
if promotion_code
|
||||
# Apply the promotion code to the order
|
||||
@order.promotion_codes << promotion_code
|
||||
@order.calculate_total!
|
||||
@total_amount = @order.total_amount_cents
|
||||
flash.now[:notice] = "Code promotionnel appliqué: #{promotion_code.code}"
|
||||
else
|
||||
flash.now[:alert] = "Code promotionnel invalide"
|
||||
end
|
||||
end
|
||||
|
||||
# For free orders, automatically mark as paid and redirect to success
|
||||
if @order.free?
|
||||
@order.mark_as_paid!
|
||||
|
||||
Reference in New Issue
Block a user