When a simple product with downloads gets converted into a variable
product all the existing download permissions for past orders become
invalid. This commit adds an extra verification procedure to the
product save code:
- Get all the existing download permissions for the product and all
the children (variations)
- For each download permission for the parent product, if there's a
variation that offers the same file for download (same file URL)
AND an equivalent download permission doesn't exist (equivalent means
same file URL, same order id and same user id), then create it.
Additionally, a new WC_Customer_Download_Data_Store::create_from_data
method is added.
This commit replaces double quotes with single quotes inside a MySQL query to avoid a syntax error when the SQL mode ANSI_QUOTES is enabled in MySQL. When this mode is enabled, MySQL treats double quotes as identifiers (like the backtick character) instead of as string delimiters. Before this change, sites running with this mode enabled wouldn't be able to add products to orders created manually in the admin as the modified query would fail (other places that also use product search including variations would fail as well). The commit that introduced this issue shipped in WC 4.5.0 (see https://github.com/woocommerce/woocommerce/pull/27171).
With PHP 8.0, non-strict comparisons between integers and strings containing
non-numeric characters are being tightened. This affects comparisons like:
0 < '0000-00-00 00:00:00'
PHP 8.0 that equates to true whereas prior to 8.0 it would be false.
More details of this change can be found at: https://wiki.php.net/rfc/string_to_number_comparison
There's a number of places in the WooCommerce codebase where the
built-in function 'round' is executed passing a non-numeric value
(not a number and not a string that can be parsed as a number),
for example round(''). In PHP 7 this yields a value of 0, but in
PHP 8 this throws an error.
This commit adds a 'NumberUtil' class with a static 'round' method,
this method checks if the passed value is numeric and if so it just
executes the built-in function, otherwise it returns 0. And all the
calls to 'round' in the codebase are replaced with 'NumberUtil::round'.
Modify the increment and decrement SQL query in
WC_Product_Data_Store_CPT::update_product_stock to be atomic. This fixes
a race condition in concurrent order placement.
When searched in a case sensitive manner, the conversion to lowercase causes uppercase matches that would have been found to be lost. This change increases the tolerance of the OR search format while also removing this unintended side-effect.
When creating an order, if manage inventory is enabled then add a `_held_for_checkout` record with a expiry timestamp embedded. This is added in an atomic manner along with making a check whether we have current stock or not.
This record is removed when order status goes to either `processing` or `completed`.