-
Notifications
You must be signed in to change notification settings - Fork 215
Product Collection: Add support for filtering products by featured status #11522
Product Collection: Add support for filtering products by featured status #11522
Conversation
- Added `featured` attribute to `ProductCollectionQuery` type to enable filtering by featured status. - Implemented `FeaturedProductsControl` to provide a toggle option in the inspector controls. - Integrated `FeaturedProductsControl` into `ProductCollectionInspectorControls`. - Added `get_featured_query` function in `ProductCollection` class to generate query for fetching featured products. - Updated existing functions and queries in `ProductCollection` class to support featured products filtering.
|
The release ZIP for this PR is accessible via: Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
3abfa1f to
9fc5471
Compare
|
Size Change: +88 B (0%) Total Size: 1.54 MB
ℹ️ View Unchanged
|
This commit makes the handling of the 'featured' parameter consistent in the ProductCollection class. Previously, the 'featured' parameter was being type-casted to boolean, which was not necessary and could lead to incorrect results. Now, the 'featured' parameter is used directly without type-casting, and the check for 'featured' products in the get_featured_query method has been updated accordingly. This ensures that the 'featured' parameter is handled consistently and correctly throughout the class.
This commit adds null coalescing operator to handle the case when 'featured' index is not set in the $query array. This prevents potential PHP notices or errors that may arise when trying to access an undefined index.
kmanijak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works really nice! Thanks for taking care of it!
I think the initial featured value should be added to the patterns as well. They will work fine without that but I think it's important to add them explicitly. What do you think?
|
Hi @kmanijak 👋
TBH I'm somewhat neutral on the matter. It seems reasonable to rely on the internal default values for attributes when not explicitly defined. We need to ensure that all the existing patterns still work as expected if new attribute is not defined. However, I'm open to following your suggestion. Should I go ahead & update all the patterns? 🤝 |
kmanijak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I'm somewhat neutral on the matter. It seems reasonable to rely on the internal default values for attributes when not explicitly defined. We need to ensure that all the existing patterns still work as expected if new attribute is not defined. However, I'm open to following your suggestion. Should I go ahead & update all the patterns? 🤝
I don't have any other argument for that except for being explicit. Maybe that's not that important 🤔 I'm approving and leaving decision up to you 🙌
f395b63 to
d5fc783
Compare
Got it, I will keep the patterns as they are unless we want to override the default behavior using an attribute. This would also apply to synced patterns created by users and third-party developers. 🙂 |
What
This PR introduces a new filter that allows users to filter products by their featured status. Specifically, the following changes have been made:
featuredattribute to theProductCollectionQuerytype, enabling filtering by featured status.FeaturedProductsControlto provide a toggle option in the inspector controls.ProductCollection.phpto support featured products filtering.Fixes #11358
Why
These changes allow merchants to easily display only featured products in their product collections, enhancing flexibility.
Testing Instructions
Please consider any edge cases this change may have, and also other areas of the product this may impact.
Case 1: Normal
Case 2: Resetting the value of the Featured filter
Case 3: Ensuring older blocks aren't broken (To be tested by developers only)
add/11358-product-collection-featured-products-filter.Screenshots or screencast
WooCommerce Visibility
Required:
Checklist
Required:
[type]label or a[skip-changelog]label.Conditional:
[skip-changelog]label is not present).Changelog