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

[Product Collection] Add Price Range Filter #11931

Closed
wants to merge 10 commits into from

Conversation

imanish003
Copy link
Contributor

@imanish003 imanish003 commented Nov 24, 2023

What

Adds a Price Range Filter to the Product Collection Block's Inspector Controls

  • Integration of Price Range Filter: A priceRange attribute has been added to the block's attribute, allowing merchants to define a price range for displaying products. This is particularly useful for creating more targeted and specific product displays based on pricing criteria.
  • Back-end Support and Filtering Logic: Corresponding back-end adjustments in ProductCollection.php ensure that the product query accounts for the new price range filter, effectively filtering products within the specified price boundaries.
  • Use of 'Auto' for Price Values: The implementation allows for dynamic price range selection with an 'Auto' placeholder. When the price fields are left blank (auto), the filter dynamically adjusts the range to include all products, offering flexibility in how the price range is applied.

Fixes woocommerce/woocommerce#42377

Why

This update significantly improves the versatility of the Product Collection block, empowering merchants to curate products more effectively based on price ranges, and thus enhancing the shopping experience for customers.

Testing Instructions

Please consider any edge cases this change may have, and also other areas of the product this may impact.

  1. Insert a product collection block into a new post.
  2. From the Filters dropdown, select the “Price Range” filter. It will appear as shown:
  1. Adjust the MIN & MAX values. Ensure that the products displayed in the Editor are filtered according to these updated values.
    • Note: The changes will only take effect if you hit ENTER or click elsewhere. This is designed to prevent unnecessary API calls while the merchant is adjusting the value.
  2. Save the modifications and confirm that the same updates are visible on the Frontend.
  3. Ensure that you can reset the filter's value by clicking in two different places, as indicated in the screenshot below:
  • Do not include in the Testing Notes
  • Should be tested by the development team exclusively

Screenshots or screencast

Before After

WooCommerce Visibility

Required:

  • WooCommerce Core
  • Feature plugin
  • Experimental
  • N/A

Checklist

Required:

  • This PR has either a [type] label or a [skip-changelog] label.
  • This PR is assigned to a milestone.

Conditional:

  • This PR has a UI change and has been cross-browser tested at different viewport sizes on both the frontend and in the editor.
  • This PR has a changelog description (if [skip-changelog] label is not present).
  • This PR adds/removes a feature flag & I've updated this doc.
  • This PR adds/removes an experimental interfaces, and I've updated this doc.
  • This PR has been accessibility tested.
  • This PR has had any necessary documentation added/updated.

Changelog

Product Collection - Add Price Range Filter

- Introduced 'priceRange' attribute in the DEFAULT_QUERY and DEFAULT_FILTERS within `constants.ts` to initialize the new price range filter.
- Added new SCSS rules in `editor.scss` for styling the price range control.
- Implemented `PriceRangeControl` in `inspector-controls/index.tsx` to enable users to specify a price range for product filtering.
- Created `PriceTextField.tsx` and `index.tsx` under `inspector-controls/price-range-control`, providing the UI for entering minimum and maximum price values.
- Extended the `ProductCollectionQuery` and `PriceRange` interfaces in `types.ts` to type-check the new price range functionality.
- Updated `ProductCollection.php` to handle the price range data when constructing the product query, ensuring products are filtered based on the specified price range.
Copy link
Contributor

github-actions bot commented Nov 24, 2023

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-11931.zip

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
product-collection-style.js wc-price-format ⚠️

This comment was automatically generated by the ./github/compare-assets action.

TypeScript Errors Report

  • Files with errors: 514
  • Total errors: 1912

⚠️ ⚠️ This PR introduces new TS errors on 1 files:

assets/js/blocks/product-collection/edit/inspector-controls/price-range-control/index.tsx

comments-aggregator

Copy link
Contributor

github-actions bot commented Nov 24, 2023

Size Change: +406 B (0%)

Total Size: 1.61 MB

Filename Size Change
build/product-collection.js 14.2 kB +369 B (+3%)
build/product-query.js 11.7 kB +8 B (0%)
build/wc-blocks-editor-style-rtl.css 7.31 kB +15 B (0%)
build/wc-blocks-editor-style.css 7.3 kB +14 B (0%)
ℹ️ View Unchanged
Filename Size
build/3810-frontend.js 18.3 kB
build/4124-frontend.js 23.9 kB
build/8280-frontend.js 8.47 kB
build/active-filters-frontend.js 6.71 kB
build/active-filters-rtl.css 1.68 kB
build/active-filters-wrapper-frontend.js 6.91 kB
build/active-filters-wrapper-rtl.css 1.53 kB
build/active-filters-wrapper.css 1.53 kB
build/active-filters.css 1.68 kB
build/active-filters.js 6.06 kB
build/add-to-cart-form-rtl.css 443 B
build/add-to-cart-form.css 443 B
build/all-products-frontend.js 9.67 kB
build/all-products-rtl.css 4.54 kB
build/all-products.css 4.54 kB
build/all-products.js 39.7 kB
build/all-reviews-rtl.css 1.75 kB
build/all-reviews.css 1.75 kB
build/all-reviews.js 7.8 kB
build/attribute-filter-frontend.js 19.9 kB
build/attribute-filter-rtl.css 4.03 kB
build/attribute-filter-wrapper-frontend.js 21.1 kB
build/attribute-filter-wrapper-rtl.css 3.89 kB
build/attribute-filter-wrapper.css 3.88 kB
build/attribute-filter.css 4.01 kB
build/attribute-filter.js 11.3 kB
build/blocks-checkout.js 33.7 kB
build/blocks-components.js 32.6 kB
build/breadcrumbs-rtl.css 234 B
build/breadcrumbs.css 234 B
build/breadcrumbs.js 2.13 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.4 kB
build/cart-blocks/cart-accepted-payment-methods-style.js 153 B
build/cart-blocks/cart-cross-sells-frontend.js 267 B
build/cart-blocks/cart-cross-sells-products-frontend.js 5.57 kB
build/cart-blocks/cart-cross-sells-products-style.js 153 B
build/cart-blocks/cart-cross-sells-style.js 269 B
build/cart-blocks/cart-express-payment-frontend.js 5.38 kB
build/cart-blocks/cart-express-payment-style.js 155 B
build/cart-blocks/cart-items-frontend.js 281 B
build/cart-blocks/cart-items-style.js 240 B
build/cart-blocks/cart-line-items-frontend.js 9.24 kB
build/cart-blocks/cart-line-items-style.js 153 B
build/cart-blocks/cart-order-summary-frontend.js 20.6 kB
build/cart-blocks/cart-order-summary-style.js 339 B
build/cart-blocks/cart-totals-frontend.js 296 B
build/cart-blocks/cart-totals-style.js 253 B
build/cart-blocks/empty-cart-frontend.js 376 B
build/cart-blocks/empty-cart-style.js 375 B
build/cart-blocks/filled-cart-frontend.js 614 B
build/cart-blocks/filled-cart-style.js 332 B
build/cart-blocks/order-summary-coupon-form-frontend.js 21 kB
build/cart-blocks/order-summary-coupon-form-style.js 155 B
build/cart-blocks/order-summary-discount-frontend.js 21 kB
build/cart-blocks/order-summary-discount-style.js 155 B
build/cart-blocks/order-summary-fee-frontend.js 288 B
build/cart-blocks/order-summary-fee-style.js 153 B
build/cart-blocks/order-summary-heading-frontend.js 347 B
build/cart-blocks/order-summary-heading-style.js 351 B
build/cart-blocks/order-summary-shipping-frontend.js 20.6 kB
build/cart-blocks/order-summary-shipping-style.js 154 B
build/cart-blocks/order-summary-subtotal-frontend.js 291 B
build/cart-blocks/order-summary-subtotal-style.js 154 B
build/cart-blocks/order-summary-taxes-frontend.js 454 B
build/cart-blocks/order-summary-taxes-style.js 202 B
build/cart-blocks/proceed-to-checkout-frontend.js 7.64 kB
build/cart-blocks/proceed-to-checkout-style.js 1.09 kB
build/cart-frontend.js 29.1 kB
build/cart-rtl.css 9.22 kB
build/cart.css 9.21 kB
build/cart.js 39.8 kB
build/catalog-sorting-rtl.css 259 B
build/catalog-sorting.css 259 B
build/catalog-sorting.js 1.7 kB
build/checkout-blocks/actions-frontend.js 8.14 kB
build/checkout-blocks/actions-style.js 1.02 kB
build/checkout-blocks/billing-address-frontend.js 9.86 kB
build/checkout-blocks/billing-address-style.js 574 B
build/checkout-blocks/contact-information-frontend.js 1.66 kB
build/checkout-blocks/contact-information-style.js 653 B
build/checkout-blocks/express-payment-frontend.js 5.81 kB
build/checkout-blocks/fields-frontend.js 375 B
build/checkout-blocks/fields-style.js 342 B
build/checkout-blocks/order-note-frontend.js 673 B
build/checkout-blocks/order-summary-cart-items-frontend.js 6.49 kB
build/checkout-blocks/order-summary-cart-items-style.js 153 B
build/checkout-blocks/order-summary-coupon-form-frontend.js 21 kB
build/checkout-blocks/order-summary-coupon-form-style.js 155 B
build/checkout-blocks/order-summary-discount-frontend.js 21.1 kB
build/checkout-blocks/order-summary-discount-style.js 154 B
build/checkout-blocks/order-summary-fee-frontend.js 291 B
build/checkout-blocks/order-summary-fee-style.js 155 B
build/checkout-blocks/order-summary-frontend.js 20.6 kB
build/checkout-blocks/order-summary-shipping-frontend.js 20.6 kB
build/checkout-blocks/order-summary-shipping-style.js 154 B
build/checkout-blocks/order-summary-style.js 341 B
build/checkout-blocks/order-summary-subtotal-frontend.js 289 B
build/checkout-blocks/order-summary-subtotal-style.js 155 B
build/checkout-blocks/order-summary-taxes-frontend.js 455 B
build/checkout-blocks/order-summary-taxes-style.js 201 B
build/checkout-blocks/payment-frontend.js 14.5 kB
build/checkout-blocks/payment-style.js 500 B
build/checkout-blocks/pickup-options-frontend.js 11.2 kB
build/checkout-blocks/pickup-options-style.js 481 B
build/checkout-blocks/shipping-address-frontend.js 9.79 kB
build/checkout-blocks/shipping-address-style.js 517 B
build/checkout-blocks/shipping-method-frontend.js 1.97 kB
build/checkout-blocks/shipping-method-style.js 1.44 kB
build/checkout-blocks/shipping-methods-frontend.js 19 kB
build/checkout-blocks/shipping-methods-style.js 456 B
build/checkout-blocks/terms-frontend.js 1.56 kB
build/checkout-blocks/terms-style.js 1.03 kB
build/checkout-blocks/totals-frontend.js 338 B
build/checkout-blocks/totals-style.js 301 B
build/checkout-frontend.js 30.7 kB
build/checkout-rtl.css 8.34 kB
build/checkout.css 8.33 kB
build/checkout.js 42.6 kB
build/classic-shortcode-rtl.css 242 B
build/classic-shortcode.css 241 B
build/classic-shortcode.js 4.66 kB
build/collection-attribute-filter-frontend.js 494 B
build/collection-attribute-filter-rtl.css 3.5 kB
build/collection-attribute-filter.css 3.5 kB
build/collection-attribute-filter.js 7.75 kB
build/collection-filters.js 1.98 kB
build/collection-price-filter-frontend.js 615 B
build/collection-price-filter-rtl.css 1.07 kB
build/collection-price-filter.css 1.07 kB
build/collection-price-filter.js 3.27 kB
build/collection-stock-filter-frontend.js 396 B
build/collection-stock-filter-rtl.css 4.05 kB
build/collection-stock-filter.css 4.04 kB
build/collection-stock-filter.js 4.17 kB
build/customer-account-rtl.css 410 B
build/customer-account.css 409 B
build/customer-account.js 3.19 kB
build/featured-category-rtl.css 974 B
build/featured-category.css 973 B
build/featured-category.js 13.6 kB
build/featured-product-rtl.css 1.02 kB
build/featured-product.css 1.02 kB
build/featured-product.js 13.9 kB
build/filter-wrapper-frontend.js 14.6 kB
build/filter-wrapper-rtl.css 378 B
build/filter-wrapper.css 378 B
build/filter-wrapper.js 2.38 kB
build/handpicked-products.js 7.34 kB
build/legacy-template-rtl.css 240 B
build/legacy-template.css 240 B
build/legacy-template.js 7.85 kB
build/mini-cart-component-frontend.js 30.8 kB
build/mini-cart-contents-block/cart-button-frontend.js 1.86 kB
build/mini-cart-contents-block/cart-button-style.js 1.23 kB
build/mini-cart-contents-block/checkout-button-frontend.js 1.95 kB
build/mini-cart-contents-block/checkout-button-style.js 1.44 kB
build/mini-cart-contents-block/empty-cart-frontend.js 383 B
build/mini-cart-contents-block/empty-cart-style.js 387 B
build/mini-cart-contents-block/filled-cart-frontend.js 284 B
build/mini-cart-contents-block/filled-cart-style.js 287 B
build/mini-cart-contents-block/footer-frontend.js 3.87 kB
build/mini-cart-contents-block/footer-style.js 1.96 kB
build/mini-cart-contents-block/items-frontend.js 246 B
build/mini-cart-contents-block/items-style.js 250 B
build/mini-cart-contents-block/products-table-frontend.js 8.59 kB
build/mini-cart-contents-block/shopping-button-frontend.js 501 B
build/mini-cart-contents-block/shopping-button-style.js 361 B
build/mini-cart-contents-block/title-frontend.js 2.04 kB
build/mini-cart-contents-block/title-items-counter-frontend.js 1.74 kB
build/mini-cart-contents-block/title-items-counter-style.js 1.2 kB
build/mini-cart-contents-block/title-label-frontend.js 1.68 kB
build/mini-cart-contents-block/title-label-style.js 1.14 kB
build/mini-cart-contents-block/title-style.js 1.38 kB
build/mini-cart-contents-rtl.css 3.23 kB
build/mini-cart-contents.css 3.22 kB
build/mini-cart-contents.js 16 kB
build/mini-cart-frontend.js 2.35 kB
build/mini-cart-rtl.css 2.44 kB
build/mini-cart.css 2.44 kB
build/mini-cart.js 6.1 kB
build/order-confirmation-additional-information-rtl.css 366 B
build/order-confirmation-additional-information.css 366 B
build/order-confirmation-additional-information.js 1.58 kB
build/order-confirmation-billing-address-rtl.css 396 B
build/order-confirmation-billing-address.css 396 B
build/order-confirmation-billing-address.js 1.56 kB
build/order-confirmation-billing-wrapper.js 1.51 kB
build/order-confirmation-downloads-rtl.css 476 B
build/order-confirmation-downloads-wrapper.js 1.58 kB
build/order-confirmation-downloads.css 477 B
build/order-confirmation-downloads.js 1.91 kB
build/order-confirmation-shipping-address-rtl.css 452 B
build/order-confirmation-shipping-address.css 452 B
build/order-confirmation-shipping-address.js 1.56 kB
build/order-confirmation-shipping-wrapper.js 1.52 kB
build/order-confirmation-status-rtl.css 280 B
build/order-confirmation-status.css 280 B
build/order-confirmation-status.js 1.55 kB
build/order-confirmation-summary-rtl.css 460 B
build/order-confirmation-summary.css 460 B
build/order-confirmation-summary.js 1.76 kB
build/order-confirmation-totals-rtl.css 586 B
build/order-confirmation-totals-wrapper.js 1.8 kB
build/order-confirmation-totals.css 585 B
build/order-confirmation-totals.js 2.18 kB
build/packages-style-rtl.css 5.19 kB
build/packages-style.css 5.19 kB
build/page-content-wrapper.js 1.97 kB
build/price-filter-frontend.js 7.94 kB
build/price-filter-rtl.css 2.68 kB
build/price-filter-wrapper-frontend.js 8.11 kB
build/price-filter-wrapper-rtl.css 2.53 kB
build/price-filter-wrapper.css 2.53 kB
build/price-filter.css 2.67 kB
build/price-filter.js 7.53 kB
build/price-format.js 913 B
build/product-add-to-cart-frontend.js 8.12 kB
build/product-add-to-cart-rtl.css 1.37 kB
build/product-add-to-cart.css 1.38 kB
build/product-add-to-cart.js 8.36 kB
build/product-average-rating-frontend.js 1.88 kB
build/product-average-rating.js 1.4 kB
build/product-best-sellers.js 7.08 kB
build/product-button-frontend.js 4.94 kB
build/product-button-interactivity-frontend.js 8.29 kB
build/product-button-rtl.css 1.14 kB
build/product-button.css 1.14 kB
build/product-button.js 4.66 kB
build/product-categories-rtl.css 654 B
build/product-categories.css 654 B
build/product-categories.js 2.6 kB
build/product-category.js 8.01 kB
build/product-collection-no-results.js 1.66 kB
build/product-details-rtl.css 397 B
build/product-details.css 394 B
build/product-gallery-frontend.js 778 B
build/product-gallery-large-image-frontend.js 604 B
build/product-gallery-large-image-next-previous.js 4.27 kB
build/product-gallery-large-image.js 2.47 kB
build/product-gallery-pager.js 3.48 kB
build/product-gallery-rtl.css 1.65 kB
build/product-gallery-thumbnails.js 3.98 kB
build/product-gallery.css 1.65 kB
build/product-gallery.js 9.67 kB
build/product-image-frontend.js 2.9 kB
build/product-image-gallery-rtl.css 307 B
build/product-image-gallery.css 306 B
build/product-image-rtl.css 996 B
build/product-image.css 994 B
build/product-image.js 2.58 kB
build/product-new.js 7.95 kB
build/product-on-sale.js 7.33 kB
build/product-price-frontend.js 2.82 kB
build/product-price-rtl.css 644 B
build/product-price.css 643 B
build/product-price.js 2.34 kB
build/product-query-rtl.css 350 B
build/product-query.css 349 B
build/product-rating-counter-frontend.js 2.19 kB
build/product-rating-counter.js 1.7 kB
build/product-rating-frontend.js 2.53 kB
build/product-rating-rtl.css 247 B
build/product-rating-stars-frontend.js 2.43 kB
build/product-rating-stars-rtl.css 899 B
build/product-rating-stars.css 900 B
build/product-rating-stars.js 1.95 kB
build/product-rating.css 246 B
build/product-rating.js 2.04 kB
build/product-results-count-rtl.css 230 B
build/product-results-count.css 230 B
build/product-results-count.js 1.66 kB
build/product-reviews-rtl.css 458 B
build/product-reviews.css 458 B
build/product-sale-badge-frontend.js 2.01 kB
build/product-sale-badge-rtl.css 437 B
build/product-sale-badge.css 437 B
build/product-sale-badge.js 1.52 kB
build/product-search-rtl.css 419 B
build/product-search.css 417 B
build/product-search.js 2.62 kB
build/product-sku-frontend.js 2.02 kB
build/product-sku-rtl.css 240 B
build/product-sku.css 239 B
build/product-sku.js 1.53 kB
build/product-stock-indicator-frontend.js 2.2 kB
build/product-stock-indicator-rtl.css 232 B
build/product-stock-indicator.css 232 B
build/product-stock-indicator.js 1.71 kB
build/product-summary-frontend.js 2.36 kB
build/product-summary-rtl.css 549 B
build/product-summary.css 549 B
build/product-summary.js 1.88 kB
build/product-tag.js 7.53 kB
build/product-template-rtl.css 548 B
build/product-template.css 547 B
build/product-template.js 2.81 kB
build/product-title-frontend.js 2.31 kB
build/product-title-rtl.css 693 B
build/product-title.css 694 B
build/product-title.js 2.05 kB
build/product-top-rated.js 7.61 kB
build/products-by-attribute.js 8.05 kB
build/rating-filter-frontend.js 18.8 kB
build/rating-filter-rtl.css 4.09 kB
build/rating-filter-wrapper-frontend.js 19.7 kB
build/rating-filter-wrapper-rtl.css 3.95 kB
build/rating-filter-wrapper.css 3.95 kB
build/rating-filter.css 4.08 kB
build/rating-filter.js 5.8 kB
build/reviews-by-category-rtl.css 1.75 kB
build/reviews-by-category.css 1.75 kB
build/reviews-by-category.js 11.4 kB
build/reviews-by-product-rtl.css 1.75 kB
build/reviews-by-product.css 1.75 kB
build/reviews-by-product.js 12.7 kB
build/reviews-frontend.js 6.44 kB
build/single-product-rtl.css 378 B
build/single-product.css 378 B
build/single-product.js 11.1 kB
build/stock-filter-frontend.js 19 kB
build/stock-filter-rtl.css 3.88 kB
build/stock-filter-wrapper-frontend.js 20 kB
build/stock-filter-wrapper-rtl.css 3.75 kB
build/stock-filter-wrapper.css 3.74 kB
build/stock-filter.css 3.87 kB
build/stock-filter.js 6.44 kB
build/store-notices-rtl.css 1.31 kB
build/store-notices.css 1.3 kB
build/store-notices.js 2.34 kB
build/wc-blocks-classic-template-revert-button-style-rtl.css 240 B
build/wc-blocks-classic-template-revert-button-style.css 239 B
build/wc-blocks-classic-template-revert-button.js 1.19 kB
build/wc-blocks-data.js 19.7 kB
build/wc-blocks-google-analytics.js 1.13 kB
build/wc-blocks-middleware.js 735 B
build/wc-blocks-registry.js 2.75 kB
build/wc-blocks-rtl.css 2.48 kB
build/wc-blocks-shared-context.js 860 B
build/wc-blocks-shared-hocs.js 1.41 kB
build/wc-blocks-vendors.js 61.9 kB
build/wc-blocks.css 2.48 kB
build/wc-blocks.js 9.19 kB
build/wc-interactivity-dropdown.js 493 B
build/wc-interactivity.js 12.7 kB
build/wc-payment-method-bacs.js 405 B
build/wc-payment-method-cheque.js 402 B
build/wc-payment-method-cod.js 508 B
build/wc-payment-method-paypal.js 439 B
build/wc-settings.js 2.42 kB
build/wc-shipping-method-pickup-location.js 29.4 kB

compressed-size-action

@imanish003 imanish003 added focus: blocks Specific work involving or impacting how blocks behave. type: task The issue is an internally driven task (e.g. from another A8c team). block: product collection Issues related to the Product Collection block labels Nov 24, 2023
@imanish003 imanish003 marked this pull request as ready for review November 24, 2023 12:19
@woocommercebot woocommercebot requested review from a team and kmanijak and removed request for a team November 24, 2023 12:19
Copy link
Contributor

@kmanijak kmanijak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm playing with the Price Range and here are some issues:

🔴 Filter doesn't work correctly

Please check the video below, where products with price €54 are filter out when setting MIN value at €46 (if I set min in euro... 🤔).
https://github.com/woocommerce/woocommerce-blocks/assets/20098064/c8207f67-db8a-41de-a1b5-b3948e465735

Another video with max, filtering out product with price €108.90 is filtered out with MAX value €89

max-incorrect.mov

I suspected some currency clash, but my main currency is EURO, so all should be fine:
image

🟠 Lack of currency sign

As a user, I'd definitely expect the currency sign next to the inputs. That's especially important for the users using multi-currency so they know what currency they set up the limits in.

Here are some additional smaller issues/edge cases. Let me know what you think of them and if it's something you think is worth addressing or we accept that for now:

Min greater than Max

It's possible to insert min value greater than max. Product Collection behaves fine, showing "No Results" and obviously it's a merchant's responsibility to make sure it's configured properly.

So probably it's not a must-have but wanted to mention anyway:

image

"-" sign

It's possible to insert minus "-" sign in the numbers but the number has no effect then. I know we're resuing the input and not controlling its validation so again - mentioning for the record
image

Can't apply decimals

You can input decimals but once submitted, the value is rounded to full number. I think we can give merchants a possibility to set decimals, especially that it should operate on any currency and I guess there are currencies that operate on decimals much more.

@imanish003
Copy link
Contributor Author

As a user, I'd definitely expect the currency sign next to the inputs. That's especially important for the users using multi-currency so they know what currency they set up the limits in.

Agreed! I will add the currency sign. Although, AFAIK In Editor, it will always use the base currency which is set using Settings → General → Currency options. Right?

@imanish003
Copy link
Contributor Author

@kmanijak

Min greater than Max

I agree that we can add validation, but I am not 100% sure how this functionality should work. For example, while editing the MAX value:

  • Should we show a message whenever MIN > MAX?
  • Should we discard the input whenever MIN > MAX?

Also, as you said, it doesn’t have any consequences because, in such cases, no products will be returned.

@imanish003
Copy link
Contributor Author

"-" sign

Good catch! Although it doesn’t have any issues related to functionality, I will check if I can quickly fix it because I am using NumberControl, so I think this is something which should be handled by NumberControl itself.

@imanish003
Copy link
Contributor Author

You can input decimals but once submitted, the value is rounded to full number. I think we can give merchants a possibility to set decimals, especially that it should operate on any currency and I guess there are currencies that operate on decimals much more.

Good catch! I will look into it. Thanks 🙏

- Removed the `max-width` restriction from `.wc-block-product-price-range-control` in `editor.scss`.

- Introduced currency symbol support in `PriceTextField.tsx` by importing `getCurrency` from `@woocommerce/price-format`. The currency symbol is now displayed as a suffix in the price input fields, providing a clearer context for the prices being entered.

- Implemented `step="any"` attribute in `NumberControl` within `PriceTextField.tsx`. This modification allows for more precise price inputs, accommodating prices with decimal values.
@imanish003
Copy link
Contributor Author

Filter doesn't work correctly

I haven't been able to replicate the issue yet, but I'll give it another try while working on the other feedback you provided. In the meantime, it would be really helpful if you could attempt to reproduce the issue on a new site.

@kmanijak
Copy link
Contributor

I haven't been able to replicate the issue yet, but I'll give it another try while working on the other feedback you provided. In the meantime, it would be really helpful if you could attempt to reproduce the issue on a new site.

I figured out what's the issue.

In WooCommerce -> Settings -> Tax this was my (unrecommended) setup:

image

I input prices exclusive of tax and display them including tax which means filtering was happening on the base price (exclusive of tax). I think that maybe the filtering should always happen based on the displayed prices (no matter if inclusive or exclusive of tax) so there are no misunderstandings by merchants similar to me who thought it was a bug 😅. What do you think?

For clarity - after unifying the prices filter works great. I also confirmed on another page with unified setup.

@imanish003
Copy link
Contributor Author

Hi @kmanijak 👋

Thank you so much for your valuable feedback on this PR! I've taken action on most of the points you raised:

  • Added currency sign
  • Removed the width from CSS
  • Decimal value support is now included.
  • The "Price Range" label now matches the style of other labels.

However, I haven't yet addressed the following feedback:

I input prices exclusive of tax and display them including tax which means filtering was happening on the base price (exclusive of tax). I think that maybe the filtering should always happen based on the displayed prices (no matter if inclusive or exclusive of tax) so there are no misunderstandings by merchants similar to me who thought it was a bug 😅. What do you think?

This issue is a bit complex, so I've sought some additional input (p1701251026307649-slack-C02FL3X7KR6).

Regarding the "Min greater than Max" and the "-" sign concerns, could you please review the comments I left on these links?

Once again, thank you so much for your detailed feedback. Your keen eye for detail during the PR review is greatly appreciated! 🙌🏻

@kmanijak
Copy link
Contributor

kmanijak commented Dec 5, 2023

Currency sign

Agreed! I will add the currency sign. Although, AFAIK In Editor, it will always use the base currency which is set using Settings → General → Currency options. Right?

I think so, that's my understanding 👍

Min greater than Max

I agree that we can add validation, but I am not 100% sure how this functionality should work. For example, while editing the MAX value:

  • Should we show a message whenever MIN > MAX?
  • Should we discard the input whenever MIN > MAX?
    Also, as you said, it doesn’t have any consequences because, in such cases, no products will be returned.

I'm against using messages. I was thinking that another value should be adjusted to the one you input:

  • min: 10, max: 20. You change min to 30, so both are updated to 30
  • min: 10, max: 20. You change max to 5, so both are updated to 5
    But TBH I don't think that's necessary until we introduce a Range Control. Then we'd need to apply that validation, for now I think it's alright as-is.

Minus sign

Although it doesn’t have any issues related to functionality, I will check if I can quickly fix it because I am using NumberControl, so I think this is something which should be handled by NumberControl itself.

Yes, let's ignore it. It's not important problem to solve at all and actually why would someone input minus in the middle of the number? 😆

The changes primarily focus on the following areas:
1. **Tax Adjustment Incorporation**: The logic now includes an adjustment for tax considerations. This is facilitated by the newly added `should_adjust_price_range_for_taxes()` method, which determines if the price filters need to be adjusted based on the discrepancy between price storage and display methods concerning tax inclusion.

2. **Tax Class Handling**: A new method `adjust_price_range_for_tax_classes()` has been implemented. It adjusts the price range for each tax class, ensuring accurate and relevant calculations. This method is essential for handling various tax scenarios and classes, improving the accuracy of price range filtering.

3. **Price Adjustment Logic**: The `adjust_price_value_for_tax_class()` method has been added for detailed tax adjustments. This method adjusts price values based on tax classes and the tax display settings, using logic akin to `wc_get_price_excluding_tax` and `wc_get_price_including_tax` from WooCommerce core.

4. **Meta Query Construction**: A new method `build_meta_query_for_price_range()` constructs the meta query for filtering products within the specified price range. This method simplifies and consolidates the meta query construction process.

Overall, these changes aim to make the price filtering feature more robust, especially in scenarios involving different tax setups. The update enhances the module's flexibility and accuracy in handling diverse pricing scenarios.
@imanish003 imanish003 force-pushed the 9360-product-collection-filters-price-range branch from e9e2337 to c07536c Compare December 8, 2023 08:44
Copy link
Contributor

This PR has been marked as stale because it has not seen any activity within the past 7 days. Our team uses this tool to help surface pull requests that have slipped through review.

If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Dec 15, 2023
@imanish003
Copy link
Contributor Author

I am closing this pull request because I have created the same pull request on the WooCommerce repository. Here is the link: #11931.

@imanish003 imanish003 closed this Dec 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: product collection Issues related to the Product Collection block focus: blocks Specific work involving or impacting how blocks behave. status: stale Stale issues and PRs have had no updates for 60 days. type: task The issue is an internally driven task (e.g. from another A8c team).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product Collection - Filters: Price Range
2 participants