Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/shop/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def create
current_user.lock!
@shop_item.lock! if @shop_item.limited?

# recalc mod prices after lock so theyre fresh
modifiers_total = @modifiers.sum { |m| m.price_for_region(region) }
total_cost = item_total + accessories_total + modifiers_total

if @mission_submission.nil?
user_balance = current_user.balance
if total_cost > user_balance
Expand Down
4 changes: 3 additions & 1 deletion app/models/shop_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ def check_user_balance
return if redeeming_mission_submission.present?
return unless frozen_item_price&.positive? && quantity.present?

total_cost_for_validation = frozen_item_price * quantity
# include modifier costs in the balance check
modifier_cost = frozen_modifiers_price || 0
total_cost_for_validation = (frozen_item_price * quantity) + modifier_cost
if user&.balance&.< total_cost_for_validation
shortage = total_cost_for_validation - (user.balance || 0)
errors.add(:base, "Insufficient balance. You need #{shortage} more tickets.")
Expand Down