Skip to content

Commit

Permalink
[Experimental] Fix minor issues of new filter blocks (#45305)
Browse files Browse the repository at this point in the history
* fix: make the dropdown hidden by default

* fix: price clause

* fix: variable name in attribute clause generator

* chore: changelog

* fix: flashing issue for dropdown has selected items
  • Loading branch information
dinhtungdu committed Mar 8, 2024
1 parent ebd54a7 commit 8e200a3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions plugins/woocommerce/changelog/fix-product-filter-minor-fixes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Experimental: fixes some minor issue with new filter blocks: query clause and initial dropdown style


Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function render( $props ) {
<div class="wc-interactivity-dropdown__dropdown" tabindex="-1" >
<div class="wc-interactivity-dropdown__dropdown-selection" id="options-dropdown" tabindex="0" aria-haspopup="listbox">
<span class="wc-interactivity-dropdown__placeholder" data-wc-text="state.placeholderText">
<?php echo esc_html( $placeholder ); ?>
<?php echo empty( $selected_items ) ? esc_html( $placeholder ) : ''; ?>
</span>
<?php if ( 'multiple' === $select_type ) { ?>
<div class="selected-options">
Expand Down Expand Up @@ -98,7 +98,13 @@ class="wc-interactivity-dropdown__badge-remove"
</svg>
</span>
</div>
<div data-wc-bind--hidden="!context.isOpen" class="wc-interactivity-dropdown__dropdown-list" aria-labelledby="options-dropdown" role="listbox">
<div
class="wc-interactivity-dropdown__dropdown-list"
aria-labelledby="options-dropdown"
role="listbox"
data-wc-bind--hidden="!context.isOpen"
<?php echo esc_attr( $dropdown_context['isOpen'] ? '' : 'hidden' ); ?>
>
<?php
foreach ( $items as $item ) :
$context = array( 'item' => $item );
Expand Down
10 changes: 5 additions & 5 deletions plugins/woocommerce/src/Blocks/QueryFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,19 @@ private function price_filter_clauses( $args, $wp_query ) {
$min_price_filter = intval( $wp_query->get( 'min_price' ) );

if ( $adjust_for_taxes ) {
$args['where'] .= $this->get_price_filter_query_for_displayed_taxes( $min_price_filter, 'min_price', '>=' );
$args['where'] .= $this->get_price_filter_query_for_displayed_taxes( $min_price_filter, 'max_price', '>=' );
} else {
$args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.min_price >= %f ', $min_price_filter );
$args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.max_price >= %f ', $min_price_filter );
}
}

if ( $wp_query->get( 'max_price' ) ) {
$max_price_filter = intval( $wp_query->get( 'max_price' ) );

if ( $adjust_for_taxes ) {
$args['where'] .= $this->get_price_filter_query_for_displayed_taxes( $max_price_filter, 'max_price', '<=' );
$args['where'] .= $this->get_price_filter_query_for_displayed_taxes( $max_price_filter, 'min_price', '<=' );
} else {
$args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.max_price <= %f ', $max_price_filter );
$args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.min_price <= %f ', $max_price_filter );
}
}

Expand Down Expand Up @@ -475,7 +475,7 @@ private function attribute_filter_clauses( $args, $wp_query ) {
if ( ! empty( $clauses ) ) {
// "temp" is needed because the extra derived tables require an alias.
$args['where'] .= ' AND (' . join( ' temp ) AND ', $clauses ) . ' temp ))';
} elseif ( ! empty( $attributes_to_filter_by ) ) {
} elseif ( ! empty( $chosen_attributes ) ) {
$args['where'] .= ' AND 1=0';
}

Expand Down

0 comments on commit 8e200a3

Please sign in to comment.