Commit Graph

35863 Commits

Author SHA1 Message Date
Nestor Soriano bc7085b3c4 Fixes after rebasing.
- Fix a call to get_available_variations with incorrect optional arguments.
- Add code that has been removed in WC_Product_Variable::get_available_variations.
2020-07-28 09:29:01 +02:00
Nestor Soriano 2283a4c7fd Revert woocommerce_product_loop to use have_posts instead of wc_get_loop_prop( 'total' ). 2020-07-28 09:01:55 +02:00
Nestor Soriano 681401850a Adjustments in the items count calculation on the nav filtering widget.
The calculations are now consistent with the change made to the
visibility of the variable products when using one or multiple filters.
2020-07-28 09:01:55 +02: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 29843b9396 Change in the logic of is_visible_core for variable products
Now, if there are filters present the logic is as follows:

- For multiple filtering values of the same attribute:
  the product is visible if there's at least one variation
  that has one of the filtering values associated to the attribute,
  or if there's at least one variation having the attribute
  with a value of "Any".

- For filtering by more than one attribute:
  the product is visible if there's at least one variation that
  is visible for ALL the attributes according to the above rule.

Note that this is irrespective of the type of logic configured for
the filter (OR or AND).
2020-07-28 09:01:52 +02:00
Nestor Soriano 3fefe84a51 Fix: WC_Query()::adjust_posts_count failing when posts list is null. 2020-07-28 08:55:55 +02:00
Nestor Soriano c074f085cc Remove two phpcs:ignores, improve code instead 2020-07-28 08:55:55 +02:00
Nestor Soriano 9142e27a19 Adjustments in WC_Query::adjust_posts_count
Two adjustments were needed:

- Adjust the count even when there's no nav filtering in the query.
  This is necessary to present the proper products count.
  even when the woocommerce_product_is_visible filter is used.
- Account for the case where $GLOBALS['wp_query']->posts
  returns objects instead of ids (for example when viewing
  a product page).
2020-07-28 08:55:55 +02:00
Nestor Soriano 9de1306c21 Fix counters in nav filtering widgets for variable products.
After the change that registers variation attributes as terms
(in addition to reigstering them as post meta) it is now time
to modify the get_filtered_term_product_counts methods in
WC_Widget_Layered_Nav so that it works consistently for both
variable and non-variable products. The logic for the counters
is now as follows:

with OR operator:
- Simple products: count the attributes of all visible products
  (unchanged behavior).
- Variable products: count attributes corresponding to
  visible variations.

with AND operator:
- Simple products: count the attributes of visible products but only
  for products that have all the selected (unchanged behavior).
- Variable products: find all the products for which all the variations
  corresponding to the selected attributes exist and are visible,
  then count the attributes corresponding to the visible variations
  of those products.

A product is "visible" if it's published, not excluded for catalog,
and has stock. Additionally, a variable product will not be considered
visible if the parent product is not.
2020-07-28 08:55: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 e1265bfa25 Refactor WC_Helper_Product by extracting duplicated code to methods.
The new methods are create_product_variation_object and
create_product_attribute_object, they are public.
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
Nestor Soriano 50e8f27bc7 Fix visibility of variable products with layered nav filtering.
The layered nav filtering doesn't work well with variable products
when some variations have stock and other don't. When a term is
selected in the widget, a variable product having no stock for
the variation corresponding to that term but having stock for
other variations will be displayed, but it shouldn't.

This commit fixes that by introducing two changes:

- A new override of "is_visible" for WC_Product_Variable that
  looks at the supplied filters, compares them against the corresponding
  available variations and calculates the visibility based on
  the query type (OR or AND).

- A hook on the "found_posts" filter in WC_Query, that adjusts
  the posts count based on the found products visibility
  when there are filters available; this is needed to sync the
  "displaying X posts" messages and the paging when variable
  products are hidden due to stock status.

Additionally, the visibility calculated in "found_posts" is cached
as loop variables so that it isn't calculated again when actually
displaying the products.
2020-07-28 08:55:52 +02:00
Nestor Soriano ff7884bdb6 Fix total products count display when there's one single result.
Fix from "Showing all 1 results" to "Showing the single result".
2020-07-28 08:47:29 +02:00
Nestor Soriano c27283dffe Fix code sniffer errors in some files.
Fixed files:

includes/abstracts/abstract-wc-product.php
includes/class-wc-query.php
includes/wc-template-functions.php
includes/widgets/class-wc-widget-layered-nav.php
templates/loop/result-count.php
tests/unit-tests/util/class-wc-tests-wc-query.php
2020-07-28 08:47:29 +02:00
Christopher Allford 578b205b4e
Merge pull request #27123 from woocommerce/feature/jetpack-autoloader-upgrade
Upgraded Jetpack Autoloader to 2.0
2020-07-27 23:35:53 -07:00
Claudio Sanches 2df7324b0d Fixed "virtual" and "downloadable" checkboxes pointers 2020-07-27 22:43:04 -03:00
Claudio Sanches 283c82b6b4 Fixed coding standards 2020-07-27 22:42:15 -03:00
Claudio Sanches de383971eb Reset all after test 2020-07-27 22:07:46 -03:00
Claudio Sanches 2043954ceb
Fixed class name 2020-07-27 21:53:28 -03:00
Claudio Sanches 0f091406df Test WC_Cart::show_shipping() 2020-07-27 21:52:33 -03:00
Claudio Sanches 08620cf846 Make "woocommerce_shipping_cost_requires_address" strict 2020-07-27 21:49:33 -03:00
Claudio Sanches 134ab5c184 Fixed coding standards 2020-07-27 20:21:41 -03:00
Claudio Sanches 4f90307e2e Fixed "Paid By Customer" data when the orders contains refunds 2020-07-27 20:18:33 -03:00
Christopher Allford 1868cd8aaa Adjusting the shipping task order in the E2E test for setup tasks 2020-07-27 15:18:27 -07:00
Andy Skelton 3e5ce05d86
Faster foreign key check when installing/upgrading
Using WooCommerce on a multisite network using the hyperdb drop-in, the foreign key check fails although there is a foreign key.

32037e37dd/includes/class-wc-install.php (L745-L763)

The first problem is that hyperdb wasn't designed to route `information_schema` queries. After patching hyperdb, the query is routed to the correct database.

The second problem is that the query still finds zero foreign keys because `$wpdb->dbname` is blank when the query is generated. Hyperdb only has a dbname in the context of a query being executed; hyperdb extracts the table name, then maps that to the correct database.

Although we could find a way to support such `information_schema` queries, they are also not preferred because they are notoriously slow. On WordPress.com they take 300ms, versus 3ms for a `SHOW CREATE TABLE` which similarly reveals the existence of the foreign key.

The proposed changes simplify the check, make it faster, and make it work with hyperdb.
2020-07-27 16:39:42 -05:00
Christopher Allford edf1932ee9 Adjusted the OBW test for changes in WC-Admin 1.4.0 2020-07-27 14:38:43 -07:00
Claudio Sanches 4048d19a39 Added unit tests for coupon code sanitization 2020-07-27 17:44:04 -03:00
Claudio Sanches e94196cea8 Sanitize coupon code in coupon ID by code functions 2020-07-27 17:33:15 -03:00
Christopher Allford ddc1f87f8d
Update README.md
Changed `npm install` suggestion to better suggest saving the dependencies as devDependencies
2020-07-27 13:30:39 -07:00
Renovate Bot 3f784fd17f
Update dependency eslint-plugin-jest to v23.19.0 2020-07-27 20:20:12 +00:00
Claudio Sanches be106af910 Added upgrade routine to sanitize all coupon codes 2020-07-27 16:50:23 -03:00
Ron Rennick d8edcb4551 update from review feedback 2020-07-27 16:48:39 -03:00
Claudio Sanches 6ee47b0356 Prevent breakage if coupons code get updated while there's some cart sessions 2020-07-27 16:48:15 -03:00
Christopher Allford c84f2b987b
Merge pull request #26750 from woocommerce/implement/core-language-packs-updates
Add language packs automatic delivery code.
2020-07-27 12:45:58 -07:00
Claudio Sanches 42321924f0 Update the coupon code sanitization
This makes match with WP sanitization for post_title.
WP sanitize post_title using kses_init_filters() when
the current user can't use unfiltered HTML.
2020-07-27 16:45:15 -03:00
Claudio Sanches d073b9d1e3 Always run wp_filter_kses() on coupon codes.
By default it only get sanitized when editing the coupon with an user
that doesn't have unfiltered_html capability.
2020-07-27 16:42:00 -03:00
Néstor Soriano 5cf1d77438
Merge pull request #27067 from matt-h/webook-race-fix
Queue all webhooks on shutdown.
2020-07-27 18:56:27 +02:00
Matt Harrison 9f8be6e2d8
Switch to use WordPress' shutdown action instead of register_shutdown_function 2020-07-27 12:11:40 -04:00
Matt Harrison e696ac7824
Queue all webhooks on shutdown.
It is possible for a later duplicate webhook to be fired too early if
the same webhook triggers in one request more than once with the updated
changes from the second one missing if it happens too quickly.
This queues all webhook to be register on shutdown instead of just
syncronous ones to make sure all data from the request is updated first
before the webhook gets queued.
2020-07-27 12:11:40 -04:00
Nestor Soriano cc118c0c10 Fixed the number of product types in the onboarding E2E test 2020-07-27 16:49:32 +02:00
Claudio Sanches db82c98801
Merge pull request #26945 from woocommerce/fix/25233
Photoswipe: Populate alt attribute for photoswipe galleries
2020-07-27 11:35:13 -03:00
Christopher Allford 4123d048e0 Fixed the number of industries in the onboarding E2E test 2020-07-27 07:08:54 -07:00
Vedanshu Jain 0a697a693f
Merge pull request #1 from vedanshujain/merge/base
Merge/base
2020-07-27 18:42:33 +05:30
Christopher Allford 08575b1661 Added JETPACK_AUTOLOAD_DEV flag to autoloader
Since Composer assigns dev versions to locally checked out repositories (most of the time) we need to set this flag. If we don't tell the autoloader we want to use dev versions then it will always prioritize the package classes over the plugin classes.
2020-07-27 09:40:55 +02:00
Christopher Allford 5afab2b03d Removed the temporary PSR-4 autoloader
This was added to get around a limitation in the Jetpack Autoloader 1.x branch. Since dependencies could not be used before `plugins_loaded` without throwing a notice we needed a custom autoloader to run before it in order to prevent the notice from showing.
2020-07-27 09:40:55 +02:00
Christopher Allford c36ea25eb9 Updated composer lock file
Now that we've got all of the packages updated successfully we can do this!
2020-07-27 09:40:55 +02:00
Christopher Allford 77eee6d92d Updated the REST API to 1.0.11 2020-07-27 09:40:55 +02:00
Christopher Allford 3e6c4dd14a Updated WooCommerce Admin to 1.4.0-beta.1
The official PR for 1.4.0-beta.2 will be arriving next week and so I've included the first beta here in order to complete the autoloader update.
2020-07-27 09:40:55 +02:00
Renovate Bot 0897ed68fc Update dependency automattic/jetpack-autoloader to v2 2020-07-27 09:40:55 +02:00