This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for filtering products by featured status
- 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.
- Loading branch information
1 parent
732eab5
commit 9fc5471
Showing
6 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
assets/js/blocks/product-collection/inspector-controls/featured-products-control.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
BaseControl, | ||
ToggleControl, | ||
// @ts-expect-error Using experimental features | ||
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis | ||
__experimentalToolsPanelItem as ToolsPanelItem, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { QueryControlProps } from '../types'; | ||
|
||
const FeaturedProductsControl = ( props: QueryControlProps ) => { | ||
const { query, setQueryAttribute } = props; | ||
|
||
return ( | ||
<ToolsPanelItem | ||
label={ __( 'Featured', 'woo-gutenberg-products-block' ) } | ||
hasValue={ () => query.featured === true } | ||
onDeselect={ () => { | ||
setQueryAttribute( { | ||
featured: false, | ||
} ); | ||
} } | ||
> | ||
<BaseControl | ||
id="product-collection-featured-products-control" | ||
label={ __( 'Featured', 'woo-gutenberg-products-block' ) } | ||
> | ||
<ToggleControl | ||
label={ __( | ||
'Show only featured products', | ||
'woo-gutenberg-products-block' | ||
) } | ||
checked={ query.featured || false } | ||
onChange={ ( featured ) => { | ||
setQueryAttribute( { | ||
featured, | ||
} ); | ||
} } | ||
/> | ||
</BaseControl> | ||
</ToolsPanelItem> | ||
); | ||
}; | ||
|
||
export default FeaturedProductsControl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters