dace7ba296
* Add syncWithFilters attribute to Product Collection * Add SycnWithFilters Inspector Control to PC * Minor import adjustments * Move the controls to Inherit as they share the same labels * Rename the attirbute to filterable * Hide control for collections * Consume the filterable * Consume filterable attribute so it enables the filtering * Bring back file format * Bring back filterable * Move filterable from attribute to query * Improve checks * Fix incorrent function name * Add changelog * Set the default filterable value on insert * Update test selector * Add E2E tests to #49627 (#49715) * Remove unnecessary call to create new post * Fix "Use page context" control tests * Fix post ↔ template collection sync test * Fix non-thenable linter errors * Extend the "Use page context" default setting test * Add test for filtering in non-archive context * Add test for combining editor and front-end filters * Fix lint * Update plugins/woocommerce-blocks/assets/js/blocks/product-collection/edit/inspector-controls/inherit-query-control.tsx Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com> * Improve query properties access * Rename inherit-query-control to use-page-context-control to better depict its purpose * Lint fix --------- Co-authored-by: Bart Kalisz <bartlomiej.kalisz@gmail.com> Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com> |
||
---|---|---|
.. | ||
README.md | ||
best-sellers.tsx | ||
featured.tsx | ||
index.tsx | ||
new-arrivals.tsx | ||
on-sale.tsx | ||
product-collection.tsx | ||
top-rated.tsx |
README.md
Product Collection - Collections
Note: Collections documented here are internal implementation. It's not a way to register custom Collections, however we're going to expose public API for that.
Collections are a variations of Product Collection block with the predefined attributes which includes:
- UI aspect - you can define layout, number of columns etc.
- Query - specify the filters and sorting of the products
- Inner blocks structure - define the Product Template structure
Interface
Collections are in fact Variations and they are registered via Variation API. Hence they should follow the BlockVariation type, providing at least:
type Collection ={
name: string;
title: string;
icon: Icon;
description: string;
attributes: ProductCollectionAttributes;
innerBlocks: InnerBlockTemplate[];
isActive?:
(blockAttrs: BlockAttributes, variationAttributes: BlockAttributes) => boolean;
}
Please be aware you can specify isActive
function, but if not, the default one will compare the variation's name
with attributes.collection
value.
As an example please follow ./new-arrivals.tsx
.
Collection can hide Inspector Controls filters from users
Let's take New Arrivals as an example. What defines New Arrivals is the product order: from newest to oldest. Users can apply additional filters on top of it, for example, "On Sale" but shouldn't be able to change ordering because that would no longer be New Arrivals Collection.
To achieve this add additional property to collection definition:
type Collection = {
...;
hideControls: FilterName[];
}
Registering Collection
To register collection import it in ./index.ts
file and add to the collections
array.