fix(checkout): prevent spurious create_order on load and ensure discount_code is always a string#513
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
|
Performance Test Results Performance test results for 983ff55 are in 🛎️! URL:
|
…unt_code is always a string
- Always initialize discount_code to '' in get_checkout_variables() so
wu_checkout.discount_code is never undefined in JS. An undefined value
caused the Vue discount_code watcher to fire a spurious create_order()
AJAX call on page load when v-init set the field to an empty string.
- Add || '' fallback in checkout.js initial data for defensive safety.
- Use explicit 'true'/'false' strings for v-init:toggle_discount_code in
class-signup-field-discount-code.php. PHP false becomes an empty HTML
attribute (""), which Vue evaluates as undefined — causing the
toggle_discount_code watcher to fire and clear discount_code on load.
- Update checkout.min.js to match checkout.js.
- Add test asserting discount_code is always a string in checkout variables.
Closes #76
85d2a95 to
6f399d4
Compare
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
Summary
discount_codeto''inget_checkout_variables()sowu_checkout.discount_codeis neverundefinedin JS. Anundefinedvalue caused the Vuediscount_codewatcher to fire a spuriouscreate_order()AJAX call on page load whenv-initset the field to an empty string.|| ''fallback incheckout.jsinitial data as a defensive guard.'true'/'false'strings forv-init:toggle_discount_codeinclass-signup-field-discount-code.php. PHPfalsebecomes an empty HTML attribute (""), which Vue evaluates asundefined— causing thetoggle_discount_codewatcher to fire and cleardiscount_codeon page load even when no coupon is pre-applied.checkout.min.jsto matchcheckout.js.discount_codeis always a string in checkout variables.Root Cause Analysis
Issue #76 reported two bugs:
toggle_discount_code = falseto the remove button click handler insimple.php).The remaining rendering bug:
wu_checkout.discount_codewas only set in$variableswhen a coupon was pre-applied. When no coupon was present, the key was absent, makingwu_checkout.discount_codeundefinedin JS. The Vuediscount_codewatcher fires when the value changes fromundefinedto''(viav-init), triggering a spuriouscreate_order()AJAX call on every page load.Additionally,
v-init:toggle_discount_codewas set to a PHP booleanfalse, whichesc_attr()renders as an empty string"". Vue evaluates an empty directive expression asundefined, causing thetoggle_discount_codewatcher to fire with a falsy value and cleardiscount_codeon load.Testing Evidence
self-assessedtest_checkout_variables_always_has_discount_code_string()verifiesdiscount_codeis always a string in checkout variablesFiles Changed
inc/checkout/class-checkout.php— always initializediscount_codeto''in checkout variablesinc/checkout/signup-fields/class-signup-field-discount-code.php— use explicit'true'/'false'forv-init:toggle_discount_codeassets/js/checkout.js— add|| ''fallback forwu_checkout.discount_codeassets/js/checkout.min.js— minified version of checkout.jstests/unit/Checkout_Request_Test.php— add test for discount_code string guaranteeCloses #76