-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Fix applying coupon codes that differ only in space (e.g., "cou pon" and "coupon") #59591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix applying coupon codes that differ only in space (e.g., "cou pon" and "coupon") #59591
Conversation
e373903
to
3bbb9ec
Compare
3bbb9ec
to
ad7b4e1
Compare
📝 WalkthroughWalkthroughA patch was applied to WooCommerce to address issues with coupon codes that differ only by spaces. The caching logic for coupon code lookups was updated to use an MD5 hash of the coupon code as the cache key, rather than the raw code string, to ensure consistent handling and prevent cache-related issues. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant WooCommerce
participant Cache
participant DB
User->>WooCommerce: Attempt to apply coupon code (e.g., "cou pon")
WooCommerce->>Cache: Lookup coupon ID using MD5-hashed coupon code key
alt Cache hit
Cache-->>WooCommerce: Return coupon ID
else Cache miss
WooCommerce->>DB: Query coupon ID by code
DB-->>WooCommerce: Return coupon ID
WooCommerce->>Cache: Store coupon ID with MD5-hashed key
end
WooCommerce-->>User: Apply coupon if valid
📜 Recent review detailsConfiguration used: .coderabbit.yml 📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (1)`**/*.{php,js,ts,jsx,tsx}`: Don't trust that extension developers will follow th...
⚙️ Source: CodeRabbit Configuration File List of files the instruction was applied to:
🧠 Learnings (2)📓 Common learnings
plugins/woocommerce/changelog/wooplug-4927-coupon-code-invalid-when-similar-code-is-used-prior (3)
🧬 Code Graph Analysis (1)plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (5)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
Testing GuidelinesHi @triple0t , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submission Review Guidelines:
Changes proposed in this Pull Request:
memcached
caching engine (possibly others) doesn't work well when the key uses space. This is cause an issue when applying or editing coupons that differ only in space (e.g.cou pon
andcoupon
), because both of them are saved with the same key. Whichever is saved to cache the first, will be returned also for the other one.This PR adds md5 (it's fast, and we don't care about security in this case) hashes the code to make it unique and acceptable for
memcached
.Closes #59487, closes WOOPLUG-4927.
(For Bug Fixes) Bug introduced in PR #56319 (likely).
Screenshots or screen recordings:
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
te st
.test
.Coupon code already exists - customers will use the latest coupon with this code.
error when saving the coupon."{$code}" is an invalid coupon code.
error and both coupons can be applied.Testing that has already taken place: