Commit Graph

1008 Commits

Author SHA1 Message Date
roykho 8b0915c4e0
Flush term cache when saving product and settings closes #25375 2021-01-28 08:26:24 -08:00
Scott Kingsley Clark ceb3a0d753
Fix fatal error problems by no longer adding false to the list of orders
By adding this prevention, it also stops fatal errors (calling method on non-object) from happening down the line when working with the orders list that is always assumed to be a proper order object.

Example error this prevents:

```
Fatal error: Uncaught Error: Call to a member function get_items() on bool in /wp-content/plugins/woocommerce/includes/class-wc-order.php on line 1902
```
2021-01-25 10:11:14 -06:00
Roy Ho 4c548951f4
Merge pull request #28521 from woocommerce/fix/26475
Create additional download permissions on product save if needed
2021-01-18 06:51:57 -08:00
Nestor Soriano 544df16588 Set exception message as translatable 2021-01-18 09:18:38 +01:00
Steve Grunwell 8d3803452d Refactor the WC_Shipping_Zone_Data_Store::read() method
This commit re-works the `WC_Shipping_Zone_Data_Store::read()` method in the following ways:

1. Remove a confusing conditional (`if ( 0 !== $zone->get_id() || '0' !== $zone->get_id() ) { ... }`)
2. Return early if we're dealing with Zone 0, eliminating additional conditional steps
3. Add documentation for the "woocommerce_shipping_zone_loaded" action hook
2021-01-12 12:53:22 -05:00
Roy Ho d8b0a8558e
Merge pull request #28586 from idofri/phpdoc
Corrected data-types in phpdoc @param
2021-01-11 06:52:11 -08:00
Ido F 4be88bea4b corrected token-id data-type 2021-01-10 16:40:24 +02:00
vedanshujain 6b550ffb23 Better error messages for when coupon are held in other transactions.
Earlier, we were just showing an "Usage limit reached message", however in some cases, specially when user is logged in, we can also ask them to go to MyAccount page and cancel order if they'd like to (to free up the coupon). This will hopefully make for a better user experience.
2020-12-16 15:19:40 +05:30
Ido F 703d474e52 corrected data-types in phpdoc @param 2020-12-14 13:31:52 +02:00
Vedanshu Jain 4339aee35f
Merge pull request #27352 from juliquiron/fix/slow-wc-customer-get-operations
Added cache and filter for wc-customer get operations.
2020-12-14 09:43:04 +05:30
Nestor Soriano f0b834d1ec Move the download permissions adjustment process to a scheduled action.
Also, move all the new code from the 'WC_Product_Data_Store_CPT' class
to a new separate 'DownloadPermissionsAdjuster' class.
2020-12-10 15:40:38 +01:00
Nestor Soriano 8944792a69 Create additional download permissions on product save if needed
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.
2020-12-09 09:29:31 +01:00
Claudio Sanches 09d98a6fe0
Merge pull request #28468 from woocommerce/fix/28417
Use single quotes inside MySQL query to avoid issues with ANSI_QUOTES
2020-12-07 19:08:38 -03:00
Néstor Soriano 43f735d0f8
Merge pull request #27558 from PlexusLLC/add_before_set_stock_action 2020-12-02 15:21:05 +01:00
Rodrigo Primo de6d55eef9 Use single quotes inside MySQL query to avoid issues with ANSI_QUOTES
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).
2020-12-02 10:37:46 -03:00
pjv b4fdf17215
Update includes/data-stores/class-wc-product-data-store-cpt.php
Co-authored-by: Néstor Soriano <konamiman@konamiman.com>
2020-12-02 06:49:56 -06:00
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
pjv 49c85e9c5e Merge branch 'master' into add_before_set_stock_action 2020-10-23 13:59:02 -05:00
pjv 7909c3ca7c white space 2020-10-13 13:59:53 -05:00
pjv 98b0fcbdff add “before” stock change action hooks to CRUD transaction 2020-10-13 13:36:42 -05: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
Julià Mestieri b209b2bec3 fixup! Added PR feedback. 2020-08-31 08:28:30 +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
Julià Mestieri 83434deb42 Added PR feedback. 2020-08-27 09:05:33 +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
Julià Mestieri b2c35a5ded Added cache and filters for wc-customer get operations. 2020-08-17 11:25:54 +02: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