Skip to content

Fix 500 error in checkout caused by undefined variable#1381

Draft
cursor[bot] wants to merge 1 commit intomasterfrom
error-500---2e62gc
Draft

Fix 500 error in checkout caused by undefined variable#1381
cursor[bot] wants to merge 1 commit intomasterfrom
error-500---2e62gc

Conversation

@cursor
Copy link

@cursor cursor bot commented Mar 25, 2026

Summary

Fixes FRONTEND-REACT-6B2

This PR fixes a 500 Internal Server Error that occurred during checkout when users submitted their order.

Problem

The $quantities variable in ProductController.php was being checked with empty() before it was initialized. In PHP, empty() on an undefined variable returns true, which caused the code to always throw an "Invalid checkout request: cart is empty" exception, even when the cart contained items.

Solution

Moved the initialization of $quantities (lines 203-206) to occur before the empty() check (line 208). This ensures the variable is properly defined before validation.

Changes

  • File: laravel/app/Http/Controllers/Api/ProductController.php
  • Change: Reordered lines 203-210 to initialize $quantities before checking if it's empty

Testing

The fix ensures that:

  • Valid checkout requests with items in the cart will no longer throw the "cart is empty" exception
  • The empty check will still work correctly for truly empty carts
  • Inventory validation proceeds as intended
Open in Web Open in Cursor 

Fixes FRONTEND-REACT-6B2

The $quantities variable was being checked with empty() before it was initialized, causing the check to always return true and throw an 'Invalid checkout request: cart is empty' exception. This resulted in a 500 Internal Server Error during checkout.

Fixed by moving the initialization of $quantities before the empty() check.
@vercel
Copy link
Contributor

vercel bot commented Mar 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
empower Ignored Ignored Mar 25, 2026 7:00pm

Request Review

@codecov
Copy link

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 22.01%. Comparing base (4272cc5) to head (6daa609).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1381   +/-   ##
=======================================
  Coverage   22.01%   22.01%           
=======================================
  Files          42       42           
  Lines        1363     1363           
  Branches      176      175    -1     
=======================================
  Hits          300      300           
  Misses       1036     1036           
  Partials       27       27           
Flag Coverage Δ
api 5.82% <ø> (ø)
frontend 32.37% <ø> (ø)
Components Coverage Δ
checkout_module 5.82% <ø> (ø)
product_component 26.03% <ø> (ø)

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.

1 participant