Fix 500 error in checkout caused by undefined variable#1381
Draft
cursor[bot] wants to merge 1 commit intomasterfrom
Draft
Fix 500 error in checkout caused by undefined variable#1381cursor[bot] wants to merge 1 commit intomasterfrom
cursor[bot] wants to merge 1 commit intomasterfrom
Conversation
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.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes FRONTEND-REACT-6B2
This PR fixes a 500 Internal Server Error that occurred during checkout when users submitted their order.
Problem
The
$quantitiesvariable inProductController.phpwas being checked withempty()before it was initialized. In PHP,empty()on an undefined variable returnstrue, 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 theempty()check (line 208). This ensures the variable is properly defined before validation.Changes
laravel/app/Http/Controllers/Api/ProductController.php$quantitiesbefore checking if it's emptyTesting
The fix ensures that: