Skip to content

recalc modifier prices inside the lock so theyre fresh, also include …#774

Open
subhansh-dev wants to merge 1 commit into
hackclub:mainfrom
subhansh-dev:main
Open

recalc modifier prices inside the lock so theyre fresh, also include …#774
subhansh-dev wants to merge 1 commit into
hackclub:mainfrom
subhansh-dev:main

Conversation

@subhansh-dev

@subhansh-dev subhansh-dev commented Jul 5, 2026

Copy link
Copy Markdown

fix: include modifier costs in balance check + recalc prices inside lock

Two related bugs in the shop order flow where modifier costs weren't being handled correctly.

Bug 1: Stale modifier prices outside the lock

Modifier prices were being summed before current_user.lock! was acquired. If another request modified a modifier's price between the sum and the lock, the order would use a stale total.

Before:

modifiers_total = @modifiers.sum { |m| m.price_for_region(region) }
total_cost = item_total + accessories_total + modifiers_total

current_user.lock!
@shop_item.lock! if @shop_item.limited?

After:

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

Bug 2: Balance check ignored modifier costs

check_user_balance only validated frozen_item_price * quantity, but create_negative_payout deducted the full cost including modifiers. This meant a user could pass the balance check but still end up with a negative balance after the payout.

Before:

total_cost_for_validation = frozen_item_price * quantity

After:

modifier_cost = frozen_modifiers_price || 0
total_cost_for_validation = (frozen_item_price * quantity) + modifier_cost

Files changed

  • app/controllers/shop/orders_controller.rb - move modifier price calc inside the lock
  • app/models/shop_order.rb - include modifier costs in balance validation

@cskartikey

Copy link
Copy Markdown
Member

please properly format the PR descp! can you show the before and after?

@subhansh-dev

Copy link
Copy Markdown
Author

Done - description's been reformatted with markdown, before/after code blocks, and a clear explanation of both fixes. Let me know if anything else needs changing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants