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 for product meta lookup table incorrectly marking a product as onsale Closes #43008 #43011
Conversation
Hi , Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
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.
Hi @pintend!
Thanks for your contribution 💯. I left some feedback regarding a tiny change that we would need to make in order for this to work as intended.
Let me know what you think!
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.
did i miss that in the commit? i had it in my test query AND CAST(meta3.meta_value AS DECIMAL(10, 2)) > CAST(meta2.meta_value AS DECIMAL(10, 2))
@pintend: You did use woocommerce/plugins/woocommerce/includes/wc-product-functions.php Lines 1571 to 1578 in 0fd0c8e
|
Hey @pintend, Thanks for making the changes. I was testing this again and now I'm wondering where the original bug came from. Using the We recently merged fixes related to product sales, so something might've changed. Is there a way to reproduce this that doesn't involve changing the metadata directly in the database? This is not necessarily supported. Hardening the lookup update might still make sense, but I'd like to understand if there's something else we're missing. |
@jorgeatorres: The issue started when a 3rd party plugin created and updated product records directly in the db, although the issue should really be fixed in that plugin (which I don't have control over) I don't see the harm "fixing" it here as well, especially when in the application this is the method it uses to determine if its on sale... might as well keep the logic consistent. Although the functions dont allow a developer to create this issue, some developers might and do go around those helper functions. adding this extra check should be a safe change that protects from that even if its "useless" for most cases
my change:
it make it more consistent and prevents the issue from other plugins |
Determine if a product is on sale based on regular price, which is how its done in the WC_Product class https://github.com/woocommerce/woocommerce/blob/7122669d448acb90d0f8a7177b76baaccec2e76b/plugins/woocommerce/includes/abstracts/abstract-wc-product.php#L1633
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.
LGTM. Thanks for your patience here @pintend and for this fix. It works great.
FYI I edited the first comment by adding some testing instructions to make it easier for our team to confirm this is working correctly.
…sale Closes #43008 (#43011) * Update wc-product-functions.php Determine if a product is on sale based on regular price, which is how its done in the WC_Product class https://github.com/woocommerce/woocommerce/blob/7122669d448acb90d0f8a7177b76baaccec2e76b/plugins/woocommerce/includes/abstracts/abstract-wc-product.php#L1633 * Add changefile(s) from automation for the following project(s): woocommerce * added missing placeholders * Update 43011-patch-1 * Add changefile(s) from automation for the following project(s): woocommerce * Re-trigger CI --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Jorge A. Torres <jorge.torres@automattic.com>
…sale Closes #43008 (#43011) * Update wc-product-functions.php Determine if a product is on sale based on regular price, which is how its done in the WC_Product class https://github.com/woocommerce/woocommerce/blob/7122669d448acb90d0f8a7177b76baaccec2e76b/plugins/woocommerce/includes/abstracts/abstract-wc-product.php#L1633 * Add changefile(s) from automation for the following project(s): woocommerce * added missing placeholders * Update 43011-patch-1 * Add changefile(s) from automation for the following project(s): woocommerce * Re-trigger CI --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Jorge A. Torres <jorge.torres@automattic.com>
Determine if a product is on sale based on regular price, which is how its done in the WC_Product class
woocommerce/plugins/woocommerce/includes/abstracts/abstract-wc-product.php
Line 1634 in 7122669
Currently
$product->is_on_sale() == false
when_regular_price
and_sale_price
are the same, but the product lookup table ignores the_regular_price
and only checks that_price
and_sale_price
are the same.Submission Review Guidelines:
Changes proposed in this Pull Request:
Closes #43008 .
How to test the changes in this Pull Request:
wp eval "wc_update_product_lookup_tables_column( 'onsale' );"
.regular_price
,sale_price
andprice
all set to the same value run the following command:wp eval "wc_update_product_lookup_tables_column( 'onsale' );"
.Changelog entry
Significance
Type
Message
Use regular_price to determine if product is not sale and don't rely only on price for product_meta_lookup
Comment