Commit Graph

986 Commits

Author SHA1 Message Date
Vedanshu Jain ae163eb28b
Merge pull request #27734 from woocommerce/enhancement/optimize-wc-order
Optimize function `wc_get_orders` by priming caches beforehand
2020-11-14 12:37:44 +05:30
vedanshujain f1742e2298 Exclude user table columns as well
This is to prevent overwriting of original column data by a meta data if meta_key name is same as a column.
2020-11-13 01:02:15 +05:30
vedanshujain fdceac9866 Delete refund cache for parent order when its deleted. 2020-11-12 10:01:15 +05:30
vedanshujain 6ed8ffe850 Addressed PR review comments #27734 2020-11-10 14:23:45 +05:30
vedanshujain 3dd80d6d65 Add polyfill for wp_cache_get_multiple 2020-11-10 14:23:44 +05:30
vedanshujain 0b29232fe3 Prime caches only when needed. 2020-11-10 14:23:44 +05:30
vedanshujain eeb8851717 Minor fixups for PR #27734 2020-11-10 14:23:44 +05:30
vedanshujain 4599884dd0 Fix failing tests. 2020-11-10 14:23:43 +05:30
vedanshujain bb1e2f44ae Removed/reverted more unnecessary changes. 2020-11-10 14:23:43 +05:30
vedanshujain 12f69c2d2d Only set cache when neccessary.
This creates a tradeoff in optimizing repeated queries vs on off queries.

Another tradeoff is making more cache get calls as opposed to more SQL calls.
2020-11-10 14:23:43 +05:30
vedanshujain a5fb3178f0 Drop CacheHydration class and do it directly.
Primary reason for dropping the cache hydration is that seems like we can acheive the same results without it, so no need to add this additional complexity to our code.
2020-11-10 14:23:43 +05:30
vedanshujain 975783b2b4 Also support methods in case direct accessing key is deprecated.
For example, in case of refunds, directly accessing parent_id is deprecated, we should use get_parent_id instead.
2020-11-10 14:23:42 +05:30
vedanshujain 8ab9fd26ef Set key before trying to add values 2020-11-10 14:23:42 +05:30
vedanshujain d502407145 Use CacheHydration to speed up fetching Order data.
This also primes various caches by fetching data well in advance, this would have been individual SQL queries otherwise.
2020-11-10 14:23:42 +05:30
vedanshujain 44a226941d Refactor `read_meta` into filter_raw_data for better re-usability. 2020-11-10 14:23:41 +05:30
Néstor Soriano 09e066fc6e
Update includes/data-stores/class-wc-data-store-wp.php
Update `@since` in new function to 4.8.0
2020-11-04 13:09:52 +01:00
James Allan 82b68b4914 Use strict comparison to compare post dates
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
2020-11-02 11:10:30 +10:00
Néstor Soriano c15488d840
Merge pull request #27830 from woocommerce/php8/fix-round-function-with-non-numeric-argument 2020-10-09 08:01:44 +02:00
Nestor Soriano 52eed70f04 Add a 'NumberUtil' class with a 'round' method.
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'.
2020-10-01 11:08:51 +02:00
Nestor Soriano b1e81d02da Fix code style/sniffer errors in a few files. 2020-10-01 11:08:51 +02:00
Nestor Soriano a94ea7f51f Remove logic for storage of attribute terms for variations
A mechanism for improved filtering by attribute for variations was
introduced some time ago. This mechanism implied maintaining term
relationships for variations, where the terms were the attributes
that defined the variation.

The mechanism was reverted because it was complex and presented many
issues, but the code that created those term relationships was kept.
This pull request removes that code and the associated unit tests.
2020-09-22 16:31:06 +02:00
Nestor Soriano d691692dcd Fix: "Create variations from all attributes" on numeric attribute values
When "Create variations from all attributes" is used to create
variations it generates term relationship entries for all the generated
variations, however that doesn't happen when the term can be interpreted
as a numeric value. This is because in that case product->get_attributes
returns the attribute values as numbers, but the code that generates
the term relationships expect those to always be strings.
When manually adding a given variation this doesn't happen.

The fix is to simply strval-ize the value before using it, but it might
be worth investigating why this is happening.
2020-08-28 11:49:31 +02:00
Ramon 7610e1311e
Ensure that the return of get_the_terms is not a WP error 2020-08-21 14:07:26 -03:00
Christopher Allford 7340c9af44
Merge pull request #27171 from woocommerce/fix/25543
Added the parent's SKU to product searches for variations
2020-08-12 12:58:00 -07:00
Claudio Sanches 02cf0dfaed
Merge pull request #27239 from woocommerce/fix/package-tag
Fix usage of "package" tag in file headers
2020-08-07 13:37:24 -03:00
Néstor Soriano 76cf1e4e93
Merge pull request #27140 from woocommerce/fix/23790
Always sanitize coupon code to prevent inconsistent between admins and shop owners
2020-08-07 12:42:02 +02:00
Claudio Sanches 525db3aa21 Fixed incorrect package tags 2020-08-05 17:49:10 -03:00
Claudio Sanches d48f1d4e2e Fixed package tag usage 2020-08-05 13:36:24 -03:00
Claudio Sanches 7f233951a5 Fixed class package tag 2020-08-04 22:30:11 -03:00
Christopher Allford 78bff3b2da Added the parent's SKU to product searches for variations
Since the parent's SKU is used when the variation does not have one, we should fall back when searching for consistency.
2020-07-29 16:53:36 -07:00
Claudio Sanches 119b5d6568
Merge branch 'master' into fix/23790 2020-07-28 13:07:17 -03:00
Néstor Soriano e9d692f455 Apply suggestions from code review
Mostly adding "since 4.4.0" annotations and updating
db update functions from 4.2 to 4.4.

Co-authored-by: Claudio Sanches <contato@claudiosanches.com>
2020-07-28 09:01:55 +02:00
Nestor Soriano 9c6c0d73d8 Record attribute terms for product variations in wp_term_relationships.
Product attributes are currently recorded as terms in
wp_term_relationships (product attributes are actually taxonomies).
In the case of variable products this is true for the main product,
but not for the variations. The attributes used to define variations
are stored as post meta, but nothing is recorded in the term
relationships table.

This is a problem when using the layered nav filtering plugin,
since the attribute counters displayed are calculated based solely
on the contents of the term relationships table. Adding meta queries
would be really messy (especially when the widget is configured
with AND operator) and would probably also hurt performance.

This commit adds a change to store the attributes for variations
as term relationships, additionally to storing them as post meta.
Terms are stored on variation creation, and updated/deleted together
with the variation as appropriate. "Any" variations (stored in meta
as empty values) are not stored as terms.

Additionally, a database upgrade is included in order to backfill
terms for already existing products.
2020-07-28 08:55:55 +02:00
Nestor Soriano 752b47513d Fix code sniffer errors in some files.
Fixed files:

includes/data-stores/class-wc-product-variable-data-store-cpt.php
includes/wc-update-functions.php
2020-07-28 08:55:55 +02:00
Claudio Sanches e94196cea8 Sanitize coupon code in coupon ID by code functions 2020-07-27 17:33:15 -03:00
Claudio Sanches 9c4ac29137
Merge pull request #26565 from woocommerce/fix/26510
Allow set "order key" while creating order via CRUD
2020-07-01 12:42:18 -03:00
Claudio Sanches cac529c393
Merge pull request #26567 from woocommerce/fix/26510-created-date
Allow set "date_created" while creating orders via CRUD
2020-07-01 12:40:43 -03:00
Vedanshu Jain b45373fe0c Revert "Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout"" 2020-06-05 15:18:01 +05:30
Claudio Sanches 7534e2eba0 Allow set "date_created" while creating orders via CRUD 2020-05-20 18:04:49 -03:00
Claudio Sanches ea19190d3b Allows to set custom order_key while creating an order 2020-05-20 17:14:17 -03:00
Christopher Allford 8332410939
Merge pull request #26308 from vandekul/master
Fix matching zones query for working with sqlite
2020-05-11 19:58:17 -07:00
Claudio Sanches 85d7cdbbb4 Allow schedule coupons via CRUD 2020-05-05 16:35:10 -03:00
Susanna 07eef2d717
Fix matching zones query for working with sqlite
And probably other databases too.
2020-04-27 18:31:52 +02:00
Vedanshu Jain ee119e0a7e
Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout" 2020-04-21 15:37:21 +05:30
Claudio Sanches 58db7314a8 Added validation for product fields. 2020-04-07 11:29:54 +02:00
Vedanshu Jain 3bf473517d
Merge pull request #25708 from woocommerce/update/reserve-stock-for-checkout
Introduce a `reserved stock` class and database table to prevent race conditions during checkout
2020-04-07 02:16:22 +05:30
Mike Jolley 51aca598b9 Only implement get_query_for_stock in data store 2020-04-03 15:55:14 +01:00
Claudio Sanches 2ebd86f2dc Revert "Revert "Add support for '_held_for_checkout` records to prevent race conditions."" 2020-04-03 15:55:13 +01:00
Gennady Kovshenin ca996a8941 Fix race condition in update_product_stock
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.
2020-03-31 16:01:26 +03:00
vedanshujain 509b2c180d Set usage count as its required by usages query 2020-03-11 20:44:52 +05:30