ba4f3d4d29
* Add price range filter to Product Collection block This update introduces a price range filter feature to Product Collection. Changes include: 1. Constants Update: - Added `priceRange` as undefined in `DEFAULT_QUERY` and `DEFAULT_FILTERS` in `constants.ts`. 2. Style Adjustments: - Added CSS for `.wc-block-product-price-range-control` in `editor.scss` to align the input text to the end. 3. Component Integration: - In `inspector-controls/index.tsx`, the `PriceRangeControl` component is now imported and integrated. 4. New Components: - `PriceTextField.tsx` and `PriceRangeControl/index.tsx` have been created to handle price range inputs in the Product Collection block. 5. Backend Integration: - `PriceRange` interface added in `types.ts` for type support. - In `ProductCollection.php`, a filter (`add_price_range_filter`) is added to modify the main query based on the price range, including adjustments for tax considerations. Overall, this enhancement allows users to filter products within a specific price range. The backend adjustments ensure that the filtering respects tax settings and displays accurate prices. * Fix formatting * Fix: Price range filter not working on Editor * Improve: Share logic between Frontend & Editor * Add changelog * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Remove duplicate changelog file * Enhanced Input Control for Price Fields Key changes include: 1. **Switch to Input Control**: Replaced the NumberControl component with the more versatile InputControl. This offers better handling of currency formatting and user input. 2. **Currency Formatting Logic**: Added robust logic for formatting numbers according to the currency settings. This includes handling thousand separators, decimal places, and currency symbols. 3. **String-to-Number Conversion**: Implemented a function to convert user-entered strings back to numbers, accounting for currency symbols and separators. This ensures accurate parsing of user input for processing. 4. **Input Handling Improvements**: Modified the onChange handlers for minimum and maximum price inputs. Now, they correctly handle edge cases like undefined or zero values, maintaining consistency in the user interface and data processing. * Refactor price range query handling 1. Introduction of a new method `get_price_range_query_args()` to encapsulate the logic for handling price range queries, especially for the two edge cases: - Prices excluding tax displayed including tax. - Prices including tax displayed excluding tax. 2. Removal of direct conditionals in the `get_query_results()` method, replacing them with a call to the new `get_price_range_query_args()` method. This makes the code more modular and easier to understand. This refactor enhances readability and maintainability of the code, ensuring that special cases in price range filtering are handled more effectively. * Remove unnecessary suffix prop * Refactor PriceTextField formatting logic for currency 1. Conditional application of thousand separators: The code now checks for the existence of `currency.thousandSeparator` before applying it. This prevents potential errors when the separator is undefined. 2. Simplified decimal separator handling: Introduced a fallback for the decimal separator, defaulting to a period ('.') if not specified by the currency settings. 3. Enhanced readability and documentation: Added comments to clarify the purpose of code blocks, especially where currency symbols are added or removed, and where value normalization occurs. 4. Function renaming for clarity: Renamed `formatValueWithCurrencySymbol` to `formatCurrency`, which better reflects its purpose. * Fix onBlur issue with PriceTextField component Refactored the PriceTextField component to utilize useState for better state management. This change introduces a local state variable, 'newValue', to store the current value. The state updates occur in the handleOnChange function, ensuring that the component's state is managed efficiently. Additionally, a new function, handleOnBlur, is implemented to handle the onBlur event, updating the component's state when focus is lost. The handleEnterKeyPress function captures the 'Enter' key press, providing a more user-friendly experience by allowing users to confirm their input with the Enter key. * Fix linting error --------- Co-authored-by: github-actions <github-actions@github.com> |
||
---|---|---|
.. | ||
active-filters | ||
attribute-filter | ||
breadcrumbs | ||
cart | ||
cart-checkout-shared | ||
catalog-sorting | ||
checkout | ||
classic-shortcode | ||
classic-template | ||
collection-filters | ||
customer-account | ||
featured-items | ||
filter-wrapper | ||
handpicked-products | ||
migration-products-to-product-collection | ||
mini-cart | ||
order-confirmation | ||
page-content-wrapper | ||
price-filter | ||
product-best-sellers | ||
product-categories | ||
product-category | ||
product-collection | ||
product-gallery | ||
product-new | ||
product-on-sale | ||
product-query | ||
product-results-count | ||
product-search | ||
product-tag | ||
product-template | ||
product-top-rated | ||
products | ||
products-by-attribute | ||
rating-filter | ||
reviews | ||
shared/styles | ||
single-product | ||
stock-filter | ||
store-notices | ||
README.md |
README.md
Blocks
Our blocks are generally made up of up to 4 files:
|- block.js
|- editor.scss
|- index.js
|- style.scss
The only required file is index.js
, this sets up the block using registerBlockType
. Each block has edit and save functions.
The scss files are split so that things in style
are added to the editor and frontend, while styles in editor
are only added to the editor. Most of our blocks should use core components that won't need CSS though.
Editing
A simple edit function can live in index.js
, but most blocks are a little more complicated, so the edit function instead returns a Block component, which lives in block.js
. By using a component, we can use React lifecycle methods to fetch data or save state.
The Newest Products block is a good example to read over, this is a simple block that fetches the products and renders them using the ProductPreview component.
We include settings in the sidebar, called the Inspector in gutenberg. See an example of this.
Other blocks have the concept of an "edit state", like when you need to pick a product in the Featured Product block, or pick a category in the Products by Category block.