From a959b0a85f9b408d8bc0f3eca0dcdd4963631653 Mon Sep 17 00:00:00 2001 From: Alexandre Lara Date: Thu, 7 Mar 2024 20:07:01 -0300 Subject: [PATCH 1/2] Prevent invalid price range selection in Product Filter Price block --- .../inner-blocks/price-filter/frontend.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/price-filter/frontend.ts b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/price-filter/frontend.ts index f20810101065..715d3c50dff6 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/price-filter/frontend.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks/product-filter/inner-blocks/price-filter/frontend.ts @@ -1,7 +1,7 @@ /** * External dependencies */ -import { store, getContext } from '@woocommerce/interactivity'; +import { store, getContext, getElement } from '@woocommerce/interactivity'; import { formatPrice, getCurrency } from '@woocommerce/price-format'; import { HTMLElementEvent } from '@woocommerce/types'; @@ -70,17 +70,28 @@ store< PriceFilterStore >( 'woocommerce/product-filter-price', { type === 'min' ? Math.min( Number.isNaN( value ) ? minRange : value, - maxRange - 1 + maxPrice ) : minPrice; const currentMaxPrice = type === 'max' ? Math.max( Number.isNaN( value ) ? maxRange : value, - minRange + 1 + minPrice ) : maxPrice; + // In some occasions the input element is updated with the incorrect value. + // By using the element that triggered the event, we can ensure the correct value is used for the input. + const element = getElement(); + if ( type === 'min' ) { + element.ref.value = currentMinPrice; + } + + if ( type === 'max' ) { + element.ref.value = currentMaxPrice; + } + context.minPrice = currentMinPrice; context.maxPrice = currentMaxPrice; From a802d171b8aaa16f26b36cfd41d78109717f352e Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 7 Mar 2024 23:16:30 +0000 Subject: [PATCH 2/2] Add changefile(s) from automation for the following project(s): woocommerce-blocks --- ...nvalid-price-range-selection-in-product-filter-price-block | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 plugins/woocommerce/changelog/45403-fix-45361-invalid-price-range-selection-in-product-filter-price-block diff --git a/plugins/woocommerce/changelog/45403-fix-45361-invalid-price-range-selection-in-product-filter-price-block b/plugins/woocommerce/changelog/45403-fix-45361-invalid-price-range-selection-in-product-filter-price-block new file mode 100644 index 000000000000..c1851ce8760d --- /dev/null +++ b/plugins/woocommerce/changelog/45403-fix-45361-invalid-price-range-selection-in-product-filter-price-block @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix an issue where shoppers could select invalid price ranges in the Product Filter: Price (Beta) block \ No newline at end of file