Commit Graph

245 Commits

Author SHA1 Message Date
Nestor Soriano 4411a394dc Reintroduce adjust_posts_count, and remove unnecessary comment.
We can't remove that method since it's public, but its body has
been changed so that it just returns the input unchanged.
2020-09-10 15:17:43 +02:00
Nestor Soriano 70a1cb2f1f Revert improved filtering for variations.
This commit reverts the functionality introduced in PR #26260
(later refined by #27175, #27190, #27508) in which filtering by
attribute using the layered nav widget was improved to handle the
cases of variations out of stock. The revert is a response to the
numerous problems reported by users in Woo 4.4 and 4.5

Not all the code has been reverted, only the code that resulted in
visible functionality changes. Thus, the code that generates
term relationships for variations is still in place to keep database
consistency and to keep the reverting changes to the minimum needed.
2020-09-09 17:36:26 +02:00
Rodrigo Primo 12cc9ddf7c Merge branch 'master' of github.com:woocommerce/woocommerce 2020-09-05 11:16:09 -03:00
Rodrigo Primo 1694975910 Fix type of the WC_Query::$product_query property in the documentation 2020-09-05 11:14:57 -03:00
Rodrigo Primo be8dc533ff
Merge pull request #26957 from kevinruscoe/patch-3
Update types
2020-09-05 11:13:10 -03:00
vedanshujain ae361ed06f Add protection to run adjust methods only if product query. 2020-08-19 13:31:57 +05:30
Nestor Soriano 71fccd6a07 Fix: pagination controls not displaying in products list.
This bug was introduced in #26260. The sequence is:

1. WC_Query::adjust_posts_count runs, to handle found_posts filter,
   this indirectly executes wc_setup_loop.
2. At this point $GLOBALS['wp_query']->max_num_pages hasn't been set
   yet, and has a value of 0. Thus the loop variable total_pages
   is set to 0.
3. Later wc_setup_loop runs again and this time
   $GLOBALS['wp_query']->max_num_pages is already set, but since
   the loop variable total_pages already exists, it keeps its
   value of 0.
4. The pagination controls never show if total_pages is less than 2.

The fix consists of hooking into the_posts to set the value of
total_pages again, at that point $GLOBALS['wp_query']->max_num_pages
is already set.
2020-07-31 16:40:25 +02:00
Néstor Soriano add9fd791b
Merge pull request #27166 from xristos3490/fix/27163
[4.4] Pagination of custom product queries broken
2020-07-31 08:29:24 +02:00
Nestor Soriano 86c88f1750 Fix: incorrect adjustment of post count in WC_Query.
PR #26260 introduced a handler for 'found_posts' filter in WC_Query
class in order to adjust the count depending on the visibility
of variation products. However the handler incorrectly assumed
that the filter was triggered only when listing products, when
actually it's also triggered for any post type e.g. pages.
In these cases the post count was set to zero, which caused bugs.

Now the handler starts with the originally supplied posts count,
and only decrements it when a post is a product AND is not visible.
2020-07-30 09:32:28 +02:00
xristos3490 6485fc337c Add docblock param 2020-07-29 18:30:26 +03:00
xristos3490 4d4b9e3432 Filter found_posts only on wc_query context 2020-07-29 18:21:36 +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 3fefe84a51 Fix: WC_Query()::adjust_posts_count failing when posts list is null. 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 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 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
Ron Rennick 625857e9e1 add rating count to order by rating clause 2020-07-06 11:19:17 -03:00
Kevin Ruscoe 0a47926418
Update types
Fixed #26537
2020-07-05 13:39:26 +01:00
Rodrigo Primo 62d6b05b58 Fix Generic.Formatting.MultipleStatementAlignment violations
This commit fixes all violations of the Generic.Formatting.MultipleStatementAlignment sniff automatically using phpcbf.
2019-12-20 14:21:08 -03:00
Rodrigo Primo f06ad5d78a Replace removed WordPress.Security.NonceVerification.NoNonceVerification
WordPress Coding Standard 2.0 removed the sniff
WordPress.Security.NonceVerification.NoNonceVerification:

```
The WordPress.Security.NonceVerification sniff used the same error code for both an error as well as a warning.
The old error code NoNonceVerification is no longer used.
The error now uses the Missing error code, while the warning now uses the Recommended error code.
```

(from
d45f5e5cf3/CHANGELOG.md (200-rc1---2018-12-31))

This commit updates WooCommerce code and replaces all instances where WordPress.Security.NonceVerification.NoNonceVerification verification was used with either WordPress.Security.NonceVerification.Missing or
WordPress.Security.NonceVerification.Recommended. In a few cases WordPress.Security.NonceVerification.NoNonceVerification was used but was not needed, so instead of replacing the sniff, the line was removed. In two other cases, I removed other unrelated sniffs that were not needed.
2019-12-13 17:45:32 -03:00
Nathan Dawson 4d25b058c1 Refine static homepage check to exclude blog archive queries. Fixes #24582 2019-09-24 23:41:57 +02:00
Claudio Sanches 15aa298585
Merge pull request #23159 from woocommerce/fix/23157
If orderby is used on static homepage, force query to be a page query
2019-05-22 21:17:01 -03:00
Mike Jolley 5c07e38641 Array handling 2019-04-23 11:53:07 +01:00
Mike Jolley 0a61912a31 If orderby is used on static homepage, force page 2019-03-27 16:38:18 +00:00
Mike Jolley 122eeda7ff Avoid step rounding on query 2019-03-07 13:01:45 +00:00
Mike Jolley e7bb5a8f41 Merge branch 'master' into experiment/product-sorting-index 2019-03-07 12:49:25 +00:00
Mike Jolley e1ff1bfae9 Update from master 2019-03-06 12:37:24 +00:00
Mike Jolley 3309276e82 Renamed table to wc_product_meta_lookup 2019-02-15 12:37:45 +00:00
Mike Jolley 7b6558e1df Correct table names and updater 2019-02-12 14:04:22 +00:00
Mike Jolley 95369b98a6 Price filter with new table 2019-02-11 15:45:30 +00:00
Mike Jolley fed9631a1e Rating and sales sorting on new table 2019-02-11 15:04:05 +00:00
Mike Jolley 47b37c7104 Queries 2019-02-11 14:42:54 +00:00
Ron Rennick e1213f8432 remove the WP main query check 2019-02-01 09:49:31 -04:00
Ron Rennick 9855a18036 phpcs sniff fixes for class-wc-query.php 2019-01-31 11:18:19 -04:00
Ron Rennick f5f020e6f4 add logic for $main_query parameter in get_meta_query 2019-01-31 11:15:14 -04:00
Mike Jolley b8e60e44c0 Handle tax in price filter specific query
Co-Authored-By: Gerhard Potgieter <kloon@users.noreply.github.com>
2019-01-23 19:39:46 +00:00
Mike Jolley ed95fe2cd3
Merge pull request #22066 from Prospress/fix/22065
add is_array check to catalog ordering orderby
2019-01-22 16:25:20 +00:00
Sabuj Kundu f329cb2d75
Add $orderby and $order params to filter woocommerce_get_catalog_ordering_args
Filter woocommerce_get_catalog_ordering_args  has only one single argument $args, anyone filter this needs to detect the $orderby and $order value again which is already coded in the method where this filter returns. I hope adding two extra param $orderby and $order will make developer's life easier to hook this filter.
2018-12-18 11:07:18 +06:00
Ron Rennick 3e014ffe62 add is_array check to catalog ordering orderby 2018-11-28 08:51:05 -04:00
Ron Rennick 64621c5b36 fix phpcs sniffs in class-wc-query.php 2018-11-28 08:50:25 -04:00
David Garcia Watkins d4484f3a4b The orderby=ID argument needs to be uppercase. 2018-09-27 19:51:10 +02:00
Rodrigo Primo f175e62286
Merge pull request #20549 from woocommerce/update/improve-layered-nav-performance
Improve WC_Query::get_layered_nav_chosen_attributes() performance
2018-06-25 09:35:21 -03:00
Rodrigo Primo c1960167f4 Fix: display products on sub-subcategories when sorting parent category by price
The algorithm to add a list of product categories to the query that order products of a given category by price was including only first level sub-categories since PR #20391. This was happening because `get_terms()` when called with the argument `parent` will only return direct children. To fix this and get all children for a given product category, it was necessary to replace `parent` with the argument `child_of`. See #20554 for a more detailed description of the issue that this commit fixes.
2018-06-19 15:47:43 -03:00
Rodrigo Primo 5f6b0df7b2 PHPCS fixes 2018-06-19 15:46:33 -03:00
Rodrigo Primo 7a7130c9d0 Improve WC_Query::get_layered_nav_chosen_attributes() performance
This commits improves the performance of the method WC_Query::get_layered_nav_chosen_attributes() when a site has a significant number of product attributes. Instead of looping over all existent product attributes to find which have been passed in the request, the new code loops over all the request parameters and checks which are valid product attributes.

On a test site with 2000 product attributes, the old version of WC_Query::get_layered_nav_chosen_attributes() was responsible for 25% of the shop page generation time. With the new version, the amount that this method contributes to the page generation time is negligible.

Related #20262
2018-06-15 14:39:56 -03:00
Rodrigo Primo 35d5bf31dd phpcs fixes 2018-06-15 14:26:47 -03:00
Mike Jolley f356269e6f
Merge pull request #20391 from smazur/master
fix order by price clauses when search within terms
2018-06-05 13:52:30 +01:00
Mike Jolley f065580b24
align 2018-06-05 13:51:37 +01:00
Stanislav Mazur 6fdd71ce8f fix order by price clauses when search within terms 2018-06-05 14:01:08 +03:00
Mike Jolley 5172694a3a
Merge pull request #19477 from woocommerce/fix/infinite-scroll
Infinite scroll compatibility
2018-04-05 10:46:44 +01:00