-
Notifications
You must be signed in to change notification settings - Fork 10.8k
fix typo when calling wc_format_decimal function #60288
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
base: trunk
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughA function call within the WooCommerce product data meta box code was corrected by changing the function name from Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. ✨ Finishing Touches
🧪 Generate unit tests
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. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php (1)
572-578
: Confirm no remaining casing issues and add regression test for COGSVerified that there are no occurrences of the incorrectly cased function
wc_format_Decimal
in the repository. Next, please add or extend a regression test to cover saving a variable product withvariable_cost_value
set, asserting that:
- No fatal errors occur during save.
- The COGS value is persisted correctly on the variation.
• Suggestion: In your PHPUnit (or E2E) test suite, create a test under
tests/unit
(or the appropriate integration folder) that:
- Creates a variable product with at least one variation.
- Sets
$_POST['variable_cost_value'][0]
to a decimal string (e.g., “12.34”).- Triggers the product save routine.
- Retrieves the saved variation and asserts
get_cogs_value()
returns the expected float.Let me know if you’d like a draft test example.
🧹 Nitpick comments (1)
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php (1)
418-421
: Optional: DRY COGS value parsing to prevent future typos and keep behavior consistent.Both blocks parse and set COGS similarly. Consider a tiny private helper (e.g.,
parse_decimal_or_null($raw)
) to centralize sanitize/empty handling and callwc_format_decimal
once. This reduces the chance of future casing typos and keeps behavior uniform.Example sketch (outside the selected ranges, for illustration):
// Inside WC_Meta_Box_Product_Data private static function parse_decimal_or_null( $raw ) { $val = wc_clean( wp_unslash( $raw ) ); if ( '' === $val || is_null( $val ) ) { return null; } return (float) wc_format_decimal( $val ); }Then within the two spots:
- Product-level:
$product->set_cogs_value( self::parse_decimal_or_null( $_POST['_cogs_value'] ?? null ) );
- Variation-level:
$variation->set_cogs_value( self::parse_decimal_or_null( $_POST['variable_cost_value'][ $i ] ?? '' ) );
Also applies to: 572-578
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)
**/*.{php,js,jsx,ts,tsx}
: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable
Files:
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
**/*.{php,js,ts,jsx,tsx}
⚙️ CodeRabbit Configuration File
**/*.{php,js,ts,jsx,tsx}
: Don't trust that extension developers will follow the best practices, make sure the code:
- Guards against unexpected inputs.
- Sanitizes and validates any potentially dangerous inputs.
- Is backwards compatible.
- Is readable and intuitive.
- Has unit or E2E tests where applicable.
Files:
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
🧠 Learnings (2)
📓 Common learnings
Learnt from: samueljseay
PR: woocommerce/woocommerce#58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.
📚 Learning: 2025-06-17T07:07:53.443Z
Learnt from: samueljseay
PR: woocommerce/woocommerce#58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.
Applied to files:
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
🔇 Additional comments (1)
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php (1)
577-577
: Fatal fix: Correct function name used (wc_format_decimal
).Good catch. This removes the fatal during variation save by calling the correct helper. Matches the product-level usage earlier in this file.
Submission Review Guidelines:
Changes proposed in this Pull Request:
Closes #60287 .
(For Bug Fixes) Bug introduced in PR #54399.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Testing that has already taken place:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Changelog Entry Comment
Comment