Commit Graph

145 Commits

Author SHA1 Message Date
Nestor Soriano 958ecf1d48 Fix the SQL query to count products in the filter by attribute widget
The previous query was counting variable products twice when they
had a variation with a concrete value for the attribute and also
a variation with "Any..." value for the same attribute.
2020-09-07 16:44:14 +02:00
Nestor Soriano 43642f7835 Enhance the query for "Any" variations in filter by attribute widget.
The new query fixes a bug where variations were being counted twice:
if a product was included in both the queries then it would be counted
differently and added; e.g. when a product had two variations,
one with "Any" attribute and other with a attribute that has a value.

The new query also optimizes performance, so that filter conditions
can be improved and better indexes can be used.
2020-09-04 11:29:50 +02:00
Nestor Soriano 417bcf8fff Split the query for counting terms in the filter by attributes widget.
For performance reasons the query is split in two: one for simple
products and variations with a concrete attribute value, and another
one for variations having "Any..." as the attribute value.
2020-09-02 16:22:25 +02:00
Nestor Soriano 07b62dabbd Improve the query to retrieve "Any..."-attributed variations in filtering widget
The new query doesn't need empty attribute entries in the meta table,
therefore the code that generates them and the migration to backfill
the missing existing ones have been removed.
2020-09-01 16:47:41 +02:00
Nestor Soriano 3a583feab1 Change filter by attributes widget to count products, not variations.
Right now the filter by attributes widget counts available variations
(for variation products). This is confusing since the counter shows
numbers that are higher than the actual count of products displayed.

This commit changes the query used by the widget so that instead
of counting variations it returns the parent product ids, and then
counts the distinct values. This also covers the case of products
where some of the variations have concrete values and some have
"Any..." values.
2020-08-31 12:22:33 +02:00
Nestor Soriano a75da34a45 Fix filter by attribute widget now working for "Any..." attributes
When a variation product has an attribute with a value of "Any...",
and there's a filter by attribute widget for that attribute, then
that product won't be included in the counts displayed in the widget
(and if the count ends up being zero, the attribute won't be shown
in the widget).

This happens before since Woo 4.4, this widget works by looking at
entries in the term relationships table for varitions too
(used to do so for simple products and for "main" variable products
only), see PR #26260; but there are no such entries for
"Any..." attributes.

This commit fixes that by extending the SQL query used by the widget
to look for variations that have empty attribute values in the meta
table too.
2020-08-27 10:59:15 +02:00
Claudio Sanches d48f1d4e2e Fixed package tag usage 2020-08-05 13:36:24 -03: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 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 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
Mike Jolley 16a0a3e27e Update from master 2019-03-05 19:03:01 +00:00
Mike Jolley 7def966e4f Impoved JSON handling 2019-02-20 12:00:47 +00:00
Mike Jolley 1efe7747a8 merge conflict 2019-02-08 13:08:55 +00:00
Mike Jolley b2c33b8e34 Merge branch 'master' into performance/slow-term-queries 2019-02-07 13:49:48 +00:00
Mike Jolley 74cd1ced37 Merge branch 'fix/20710' 2019-01-31 13:37:02 +00:00
Mike Jolley 5b57cb5356 Layered nav should use base link 2019-01-30 16:29:01 +00:00
Mike Jolley fa58f3bb9f Lax the kses here - link and name is already escaped. 2019-01-30 16:10:48 +00:00
Mike Jolley a38add7ac8 No need for default sorting 2019-01-25 19:55:25 +00:00
claudiulodro 8078e6bfc2 Simplified title check that works on all wc widgets 2019-01-24 10:47:05 -08:00
Ron Rennick 8709351994 update function name to `wc_attribute_taxonomy_slug` 2019-01-23 11:11:27 -04:00
Ron Rennick b868b484f7 fix merge conflicts 2019-01-23 10:53:42 -04:00
Mike Jolley 0c76db4093 Get instance setting defaults so it shows in customiser before save 2019-01-04 16:11:36 +00:00
Gerhard 7074b0933c Don't wrap wp_json_encode string in quotes, it already does it for us. 2018-12-10 10:14:56 +02:00
Ron Rennick c1ad273a03 replace all remaining str_replace( 'pa_', ... with wc_attribute_taxonomy_name_raw(...) 2018-12-03 11:32:33 -04:00
claudiulodro 67d80c35d8 Update cache key to consistently work with all types of chars 2018-09-20 08:21:39 -07:00
Gerhard Potgieter f28002f257 Use wp_json_encode instead of esc_js. Hat tip @dtugend 2018-09-10 14:35:55 +02:00
Gerhard Potgieter 16b2abe8cd Remove charset, WP will load site charset by default. We need to do esc_js first before wp_specialchars_decode to avoid esc_js to encode double quotes again. 2018-09-10 11:58:39 +02:00
Gerhard Potgieter 6b3feb0417 Decode encoded special chars for Any string label used in the layered nav widget. 2018-09-10 10:49:25 +02:00
Rodrigo Primo 20fd569a55 Fix clearing filters in "Filter products by attribute" widget
This commit fixes an issue that was making it impossible to clear filters in the "Filter products by attribute" widget when the attribute name contained non-ASCII characters. The problem was caused by a call to sanitize_title() which doesn't seem necessary as it is sanitizing one of the widget parameters which is already sanitized in 679d719368/includes/widgets/class-wc-widget-layered-nav.php (L116). So this commit simply removes the sanitize_title() call. Even if we needed to sanitize the variable `$taxonomy`, it would be better to use sanitize_text_input_field() or wc_sanitize_taxonomy_name() as sanitize_title() will replace accented characters.

For more about the problem that is fixed by this commit see #21028
2018-08-14 11:45:57 -03:00
Mike Jolley 679d719368 Use correct escaping on placeholder
Use correct escaping on placeholder - this is not HTML, this is an attribute output within javascript code.

Closes #20360
2018-06-04 10:53:10 +01:00
Mike Jolley 06418f67e5
Merge pull request #19225 from roylindauer/17355-SplitAndFilter
Split layered nav transient per issue #17355
2018-03-14 12:50:54 +00:00
Roy Lindauer b151480e6b fix indentation issues 2018-03-13 15:34:47 -07:00
Claudio Sanches cbb1271b2c Fixed class-wc-widget-product-categories.php PHPCS violations 2018-03-09 17:28:08 -03:00
Claudio Sanches e87c309b01 Fixed class-wc-widget-layered-nav.php PHPCS violations 2018-03-09 17:10:03 -03:00
Roy Lindauer bb9afb29be
cached_counts would not be defined if cache is false 2018-03-06 07:32:12 -08:00
Roy Lindauer 4147038e93 Add filter to control caching of layered nav counts. Split cached layered nav counts by taxonomy 2018-03-02 22:14:20 -08:00
Boro Sitnikovski 080ece9588 Change method name 2017-12-14 15:37:42 +01:00
Boro Sitnikovski e1b753122e Deprecate the function as a whole 2017-12-14 10:23:51 +01:00
claudiulodro d60456cc73 Resolve conflicts and bring up to date with master 2017-12-04 13:56:59 -08:00
Mike Jolley 208b2d1b81 Slugs are encoded, so decode before outputting to the form
Fixes #17845
2017-11-21 16:50:33 +00:00
Mike Jolley 46775c2f7d standards 2017-11-20 12:14:05 +00:00
Alexandre GASNE 0018b4349e Fix: Apostrophe wrongly escaped for price nav filter and widget nav filters 2017-11-18 20:11:53 +01:00
Mike Jolley 1a7d7dd127 Widget base url 2017-11-09 11:24:29 +00:00
Mike Jolley 1b22d97be2 Combined get_page_base_url 2017-11-09 11:16:47 +00:00
Gerhard Potgieter 21377fe5a7 input to button for submit in class-wc-widget-layered-nav.php 2017-11-07 10:56:36 +02:00
Gerhard Potgieter 364d266def PHPCS fixes for class-wc-widget-layered-nav.php 2017-11-07 10:55:27 +02:00
Mike Jolley a6e5a684d0 Merge branch 'pr/17134' 2017-10-27 16:07:41 +01:00
Mike Jolley e5038e737e Standards 2017-10-27 16:07:30 +01:00
Mike Jolley 35f5140e1c Merge branch 'pr/17137' 2017-10-27 15:59:56 +01:00