Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Filter data count mismatch > Fix PHP unit tests #8984

Merged
merged 65 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
46d1c87
Introduce the new get_attribute_and_meta_counts method.
nefeline Mar 2, 2023
0fb83b2
Ensure that if no term_slug or term_id is found for counting, the def…
nefeline Mar 2, 2023
ab5ad74
update conditional for the slug, the empty state for requests without…
nefeline Mar 10, 2023
e55655c
Introduce the get_terms_list method.
nefeline Mar 10, 2023
602bf81
Remove the legacy get_attribute_counts method and update its calls to…
nefeline Mar 10, 2023
42f5063
Update the query to ensure that if a parent product has multiple iden…
nefeline Mar 10, 2023
ef9a486
Update to start relying on the get_product_by_metas method for counti…
nefeline Mar 10, 2023
ddf4533
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Mar 13, 2023
9ee08f3
Add a new where_clause to only include product metas and attributes i…
nefeline Mar 13, 2023
82446d3
Add wpdb->prepare to the macro query and the get_terms_list method.
nefeline Mar 13, 2023
c473b60
Replace the raw atomic query for fetching the filtered terms with the…
nefeline Mar 13, 2023
a41c687
Update the request params for the get_attribute_and_meta_counts method.
nefeline Mar 14, 2023
754f4ed
Update the request params for the product metas (min and max price).
nefeline Mar 14, 2023
ce07db7
Update the query and returned value on get_terms_list.
nefeline Mar 14, 2023
551a81d
Update the validation for returning the default counts when no values…
nefeline Mar 15, 2023
1cb4780
Update the query on get_terms_list to use ->prefix
nefeline Mar 15, 2023
da924fb
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Mar 21, 2023
90d37c9
Update the variable for the query to rely on the filtered one. Updat…
nefeline Mar 21, 2023
fb8895f
Ensure the get_product_by_filtered_terms method is triggered for each…
nefeline Mar 22, 2023
86ae6a5
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Mar 22, 2023
074ac6c
Make adjustments for the 'and' condition to work as expected.
nefeline Mar 22, 2023
88490af
Ensure the queryState.attributes is properly added as a param to the …
nefeline Mar 13, 2023
dbe85bf
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Mar 23, 2023
44d8bce
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Mar 26, 2023
e750d47
Ensure the get_product_by_metas method is only triggered when at leas…
nefeline Mar 26, 2023
5fddcbd
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Mar 28, 2023
77e2c11
Join type update: for the 'and' (all) filter condition, items with th…
nefeline Mar 29, 2023
d8c6ec7
wpdb prepare the where clauses
nefeline Mar 29, 2023
1276e52
Update the get_product_by_filtered_terms query wpdb prepare params
nefeline Mar 29, 2023
6408941
update the get_product_by_metas method's where clause preparation.
nefeline Mar 29, 2023
62f9910
Update the where clause preparation for get_attribute_and_meta_counts…
nefeline Mar 29, 2023
a2861c9
Adjust the get_attribute_and_meta_counts method for usage alongside t…
nefeline Mar 29, 2023
b715cef
Adjust the query for fetching the attribute counts for filtered ratings.
nefeline Mar 29, 2023
601c5a9
Add support for the filter by stock.
nefeline Mar 29, 2023
0b42527
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Mar 31, 2023
f8ba66f
Ensure the product attribute counts are correct if the parent product…
nefeline Mar 31, 2023
f77b6f8
Ensure product_or_parent_id is used only when the filter by rating is…
nefeline Mar 31, 2023
5df4e9b
Add the missing else condition.
nefeline Mar 31, 2023
200aa4f
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Apr 3, 2023
41cd373
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Apr 3, 2023
a186e85
Enable caching.
nefeline Apr 4, 2023
42d6d23
Address CR
nefeline Apr 4, 2023
c98d1ff
Update query for average rating.
nefeline Apr 4, 2023
c216e08
remove file accidentally commited.
nefeline Apr 4, 2023
f95af0b
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Apr 4, 2023
9719921
When multiple ratings are selected, make sure the where clause is upd…
nefeline Apr 5, 2023
3ee28ee
Start updating the stock_status logic to account for when multiple op…
nefeline Apr 5, 2023
f947d22
Ensure the counts are properly updated when more than one stock statu…
nefeline Apr 5, 2023
45372ae
Ditch the is_array condition for the average_rating counts as is alw…
nefeline Apr 5, 2023
be684f9
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Apr 5, 2023
640f66f
Deprecate the second param attributes for the get_attribute_counts me…
nefeline Apr 5, 2023
e00ce15
Add the filtered_attribute to the transient_key
nefeline Apr 5, 2023
497e101
Bypass cache if WP_DEBUG is enabled.
nefeline Apr 6, 2023
0694070
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Apr 6, 2023
cb40f04
Update formatting for macro query.
nefeline Apr 6, 2023
83388ce
Fix mixed tabs spaces on query
roykho Apr 6, 2023
51f3445
Fix PHP unit tests for the new attribute counts.
nefeline Apr 7, 2023
7600429
Update spacing/formatting for SQL queries.
nefeline Apr 10, 2023
42e7b9c
Minor: update indentation for the main SQL query
nefeline Apr 10, 2023
51824c5
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Apr 11, 2023
0bed05f
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Apr 11, 2023
68dac09
Merge branch 'add/get-attribute-and-meta-counts-method' into fix/php-…
nefeline Apr 11, 2023
f3f4fe5
Merge branch 'trunk' into add/get-attribute-and-meta-counts-method
nefeline Apr 11, 2023
7a4a3d6
Merge branch 'add/get-attribute-and-meta-counts-method' into fix/php-…
nefeline Apr 11, 2023
7a04ead
Merge branch 'trunk' into fix/php-unit-tests-attribute-counts
nefeline Apr 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions assets/js/blocks/attribute-filter/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ const AttributeFilterBlock = ( {
shouldSelect: blockAttributes.attributeId > 0,
} );

const filterAvailableTerms =
blockAttributes.displayStyle !== 'dropdown' &&
blockAttributes.queryType === 'and';
const { results: filteredCounts, isLoading: filteredCountsLoading } =
useCollectionData( {
queryAttribute: {
Expand All @@ -153,7 +150,6 @@ const AttributeFilterBlock = ( {
},
queryState: {
...queryState,
attributes: filterAvailableTerms ? queryState.attributes : null,
},
productIds,
isEditor,
Expand Down
43 changes: 3 additions & 40 deletions src/StoreApi/Routes/V1/ProductCollectionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,49 +91,12 @@ protected function get_route_response( \WP_REST_Request $request ) {
}

if ( ! empty( $request['calculate_attribute_counts'] ) ) {
$taxonomy__or_queries = [];
$taxonomy__and_queries = [];

foreach ( $request['calculate_attribute_counts'] as $attributes_to_count ) {
if ( ! empty( $attributes_to_count['taxonomy'] ) ) {
if ( empty( $attributes_to_count['query_type'] ) || 'or' === $attributes_to_count['query_type'] ) {
$taxonomy__or_queries[] = $attributes_to_count['taxonomy'];
} else {
$taxonomy__and_queries[] = $attributes_to_count['taxonomy'];
}
if ( ! isset( $attributes_to_count['taxonomy'] ) ) {
continue;
}
}

$data['attribute_counts'] = [];
// Or type queries need special handling because the attribute, if set, needs removing from the query first otherwise counts would not be correct.
if ( $taxonomy__or_queries ) {
foreach ( $taxonomy__or_queries as $taxonomy ) {
$filter_request = clone $request;
$filter_attributes = $filter_request->get_param( 'attributes' );

if ( ! empty( $filter_attributes ) ) {
$filter_attributes = array_filter(
$filter_attributes,
function( $query ) use ( $taxonomy ) {
return $query['attribute'] !== $taxonomy;
}
);
}

$filter_request->set_param( 'attributes', $filter_attributes );
$counts = $filters->get_attribute_counts( $filter_request, [ $taxonomy ] );

foreach ( $counts as $key => $value ) {
$data['attribute_counts'][] = (object) [
'term' => $key,
'count' => $value,
];
}
}
}

if ( $taxonomy__and_queries ) {
$counts = $filters->get_attribute_counts( $request, $taxonomy__and_queries );
$counts = $filters->get_attribute_counts( $request, $attributes_to_count['taxonomy'] );

foreach ( $counts as $key => $value ) {
$data['attribute_counts'][] = (object) [
Expand Down
Loading