* Add new Product Average Rating block
* Add new blocks to the feature flag docs
* Translate 'No ratings'
* Fix condition
* Small improvements after review
* Avoid duplication of styles
* Update supports in php class
This commit adds a new `__experimentalExpandOnFocus` attribute to the component within the `HandPickedProductsControl`. The value is set to `true`, enabling automatic expansion of the list when the user focuses on the product selection field.
This change aims to improve the user experience by making it easier for the user to see all available options when they focus on the selection list.
* Create Mini-Cart template part area
* Update Mini-Cart template part name to exclude it
* Update src/BlockTemplatesController.php
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
* Update src/BlockTemplatesController.php
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
* Keep both variations of the template part name when excluding them
* Revert "Keep both variations of the template part name when excluding them"
This reverts commit c3f293511536d1ebbac0f50caaf74cded28d0025.
---------
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
* Add cors check
* refactor logic
* Refactor add_cors_headers to allow null and allowed hosts
* Move remove_filter inline
* Revert unrelated code style changes
* Add explainer to docblock
* Remove access for null origin
* Move CORS handling to auth class so it applies API wide
* Move only Authentication to priority 11
* Handle preflight requests so cart-tokens work
---------
Co-authored-by: Mike Jolley <mike.jolley@me.com>
* Mini Cart: Replace the deprecated print_inline_script() with supported get_inline_script_data(). Fixeswoocommerce/woocommerce-blocks#10004
* Mini Cart: Add version check for the new get_inline_script_data() function
* Update the variable names and fix a typo
* Mini Cart: Add regex to check for the WP version
* Abstract the WP version comparison regex to a separate Utils class
* Remove queries that fetch all products for manipulating the results returned by the Store API for certain use-cases.
* Remove the code that's supposed to read product ids for filter context and logic around that in useCollectionData
* Fix incorrect merge
---------
Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
* Remove queries that fetch all products for manipulating the results returned by the Store API for certain use-cases.
* Keep support for Product Collection block
* Rating start block improvements
Fix classes, register in single product, remove unused code
* Allow to use block on product & product collection
* Fix star missalignment
* Restrict the block to be insertable only in single product
Key updates:
1. Additional CSS class to Inherit Query Control: A CSS class named `wc-block-product-collection__inherit-query-control` has been added to the ToggleControl component. This provides a precise target for E2E tests and potential custom styles.
2. E2E tests for 'Inherit query from template' control: Numerous scenarios have been covered to ensure the control's correct behavior. These scenarios include verifying visibility under different circumstances and checking its functionality in a Product Catalog template.
3. E2E test code enhancements: The E2E test code now exports the `SELECTORS` object to assist in locating different elements during the tests. This includes the new 'Inherit query from template' control. The `setShowOnlyProductsOnSale()` function has been refactored to improve readability and provide more granular control over its operations.
4. Test scenario for 'Show only products on sale': The existing E2E test for this functionality has been extended to check that it retains its state when the 'Inherit query from template' control is toggled.
These changes increase the robustness of our E2E tests, providing better coverage for the 'Inherit query from template' control in the Product Collection block.
* allow for handling classic theme template part support
Note this logic is currently not right - just a quick implementation for testing POC
* Account for classic theme support of template parts
* Update supports_block_templates signature so it accepts the template type instead of a bool
* Simplify logic in supports_block_templates
* Test
* Fix supports_block_templates check to test correct template type
---------
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* Foundation of the Products block replacement with Product Collection
* Provide logic to replace Products with Product Collection
* Make sure the blocks can be replaced
* Add types and refactor replacement a bit
* Fix the query attributes transform
* Add upgrade Notice to the Product Collection block
* Force upgrade notice to be displayed at the top of the Inspector Controls
* Externalise migration code so it can be reused in both ways
* Add util to get block IDs byt its name
* Add a way to revert the Product Collection blocks to Products
* Move the subscription to another place where it's triggered only once
* Add default values
* Remove attributes from Products block if they're not used to avoid incorrect query
* WIP logic of unseen/seen/reverted notice
* Change the state reading
* Revert changes regarding notice displaying logic
* Change the logc of firing replacement and bail early if there's no core/query blocks
* Add todos
* Implement inner blocks migration
* Implement the revert transformation of inner blocks
* Refactor types
* Add layout transformation from Products to Product Collection
* Add layout migration from Product Collection to Products
* Disable migration by default
* Simplify some parts of code
* Remove additional keyword from Product Collection to move it to another PR
* Adjust the logic to introduce the first step: conversion from Products to Product Collection
* Disable automatic migration
* Refactor Columns Control inspector controls in Product Collection
* Refactor Order By inspector controls in Product Collection
* Reorder imports in Product Collection Inspector Controls
* Refactor On Sale inspector controls in Product Collection
* Refactor Stock Status inspector controls in Product Collection
* Refactor Keyword inspector controls in Product Collection
* Unify interface of query controlling Inspector Controls
* Unify interfaces of Inspector Controls that modify Query in Product Collection
* Unify other Query modifying Controls
* Simplify types
* Add E2E tests for category-based product filtering
This commit refactors the product filtering in the product collection E2E tests and adds the ability to filter products based on their category.
Changes:
1. The method `setHandpickedProducts` was renamed to `setFilterComboboxValue` to reflect the fact that it's now used for more than just handpicked products. This method is now used to set the values of different filters.
2. The `addFilter` method was extended to support the 'Show Taxonomies' filter. It also includes a delay to ensure the correct rendering of the UI before further interactions.
3. A new test was added for filtering products based on their category using the 'Show Taxonomies' filter.
4. The tests for filtering products by handpicked selection and keyword were updated to use the new `setFilterComboboxValue` method.
These changes improve the robustness of the E2E tests and increase their coverage by including category-based filtering.
* Add product attribute filters to end-to-end tests
- A new test case has been added in the `product-collection.block_theme.spec.ts` to test the functionality of filtering products based on their attributes like color and size. This is done using the `addFilter` and `setProductAttribute` methods.
- Additionally, the `addFilter` method in `product-collection.page.ts` has been updated to include the 'Show Product Attributes' filter.
- A new method `setProductAttribute` has been introduced to set the attribute value which will trigger the filter action.
These updates enhance the test coverage by verifying the functionality of product attribute filters in the product collection.
* Add responsiveness test for product collection block
This commit introduces a new end-to-end test to ensure that the product collection block responds correctly to changes in screen size.
The new test in `product-collection.block_theme.spec.ts` verifies that the number of product columns adjusts as expected for different viewport sizes. In the initial viewport size, the width of a product should be less than the parent width as multiple columns are expected. When the viewport size is reduced, the product width should be approximately equal to the parent width, indicating a single column layout.
These changes provide more robust testing of the product collection block's responsiveness, helping to ensure a consistent user experience across different device sizes.
* Refactor product assertions and add setViewportSize method in ProductCollection tests
This commit refactors the Product Collection tests to enhance test readability and consistency. It switches the product count checks from `productImages` to `products` which is more semantically correct.
Additionally, a new method `setViewportSize` has been added in the `ProductCollectionPage` class for adjusting the viewport size in the tests.
- Changed product count assertions to use `products` instead of `productImages`
- Added `setViewportSize` method to `ProductCollectionPage`
- Updated existing tests to use the newly added `setViewportSize` method
* Add test case for product filtering based on stock status in Product Collection tests
This commit adds a new test case in the Product Collection suite to test product filtering based on their stock status. The test case checks if the filter for 'Out of stock' status works correctly.
Note: This test case is currently commented out because there are no products with 'Out of stock' status in the test data. The assertions will need to be uncommented once the test data includes 'Out of stock' products.
* Add new test case for toolbar settings
This commit does two main things:
1) Adds a new test case under 'Toolbar settings' to test 'Items per page', 'offset' & 'max page to show' settings in the product collection block.
2) It extends the ProductCollectionPage class to add methods for setting display settings and for handling pagination. It also defines a new 'pagination' locator to find the pagination navigation on the page.
This update will allow us to more effectively test the behavior of the product collection block when dealing with large collections and pagination. Note: the 'Product can be filtered based on stock status' test has been marked as skipped until there are products with 'Out of stock' status in the test data.
* Refactor e2e test files for Product Collection
Changes in `product-collection.block_theme.spec.ts`:
- Marked the test 'Products can be filtered based on category' as a 'fixme'. This test is currently failing due to a bug in the product collection block.
Changes in `product-collection.page.ts`:
- Reorganized constant block data into a more extensive set of selectors.
- Introduced a new method `locateSidebarSettings` to locate the sidebar settings region, improving readability and reusability.
- Used the new method `locateSidebarSettings` in various places where settings values are being set.
- Refactored other methods to better locate elements based on the reorganized selectors.
- Adjusted the product-related locators to rely on these newly defined selectors.
* Fix: Frontend Category Filtering in Product Collection Block (https://github.com/woocommerce/woocommerce-blocks/pull/10132)
* Fix: Product collection - Product category filter isn't working on frontend
* Remove fixme from test
* Refactor variables names
* Add Display Layout controls to Product Collection
* Adjust the layout type name
* Add explicit display layout types
* Change the function name to setDisplayLayout so it's more explicit
* Pass only the necessary props to nested inspector controls
---------
Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
* Add support for filter blocks
This commit updates the `ProductCollection` block implementation to add support for filter blocks, including the Price filter, Attributes filter, Rating filter, and In stock filter.
The changes include:
1. Adding a new property `$attributes_filter_query_args` to store the query arguments related to the filter by attributes block.
2. Adding a new method `add_support_for_filter_blocks()` to enable support for filter blocks. This method sets the necessary asset data to enable filtering and refreshes the page when a filter is applied.
3. Adding new methods to handle specific filter queries, including `get_filter_by_price_query()`, `get_filter_by_attributes_query()`, `get_filter_by_stock_status_query()`, and `get_filter_by_rating_query()`. These methods generate the respective queries based on the applied filters.
4. Refactoring the `get_final_query_args()` method to include the newly added filter queries using the `get_queries_by_applied_filters()` method.
These changes enhance the functionality of the `ProductCollection` block by allowing users to filter products based on price, attributes, rating, and stock status.
* Go to first page when filters are updated
* Enhance ProductCollection block to support filter blocks
This commit enhances the ProductCollection block to support various filter blocks such as Price filter block, Attributes filter block, Rating filter block, and In stock filter block.
The `build_query` method has been refactored into two separate methods: `build_frontend_query` and `get_final_frontend_query` to make the code more modular and readable. The `add_support_for_filter_blocks` method has been modified to support the generation of product IDs for filter blocks.
The method `update_rest_query` has been renamed to `update_rest_query_in_editor` for better clarity and understanding of its function. Similarly, `get_final_query_args` has been refactored to include the `$is_exclude_applied_filters` parameter which helps in generating product IDs for the filter blocks.
Moreover, the filter hook `pre_render_block` has been added to support the filtering of blocks before they are rendered.
This update will enhance the user experience by providing more filtering options in the ProductCollection block.
* Remove changes related to redirect to 1st page
* Go to first page when filters are updated
This commit refactors the changeUrl function in the `filters.ts` file. The purpose of this refactor is to remove the page number from the URL whenever filters are changed. This ensures that the user is always taken to the first page of results.
The commit includes the following changes:
- Added comments explaining the different page number formats in the URL.
- Updated the `newUrl` parameter by removing the page number using regular expressions.
- The page is then reloaded with the updated URL using `window.location.href`.
These changes improve the URL handling in the `changeUrl` function and enhance the user experience when interacting with filters.
* Optimize URL updates to prevent unnecessary page reloads
This commit optimizes the `changeUrl` utility function to prevent unnecessary page reloads.
Changes:
1. It checks if there are no query parameters in the URL and the URL ends with a '?'.
2. If these conditions are met, it removes the trailing '?' from the URL.
The reason for this change is that a '?' in the URL typically indicates that query parameters will follow. If there are no query parameters, the '?' is unnecessary and can cause the page to reload, which can negatively affect performance. Therefore, by removing the '?', we prevent this unnecessary page reload.
* Simplify trailing '?' removal in URL handling
This commit simplifies the removal of trailing '?' characters from URLs.
The previous implementation checked if there were any query parameters
before removing a trailing '?'.
However, upon review, it was determined that this check was unnecessary,
as a trailing '?' could be removed safely even if query parameters were
present, without any negative impact.
This change simplifies the code and prevents unnecessary computation
checking for the existence of query parameters.