woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-collection/collections
Karol Manijak 37155abb0c
New flow of adding Product Collection and basic set of Collections (#42696)
* Migrate PR to Core

* Migrate test changes

* Add Custom Collection with inherit query attribute disabled

* Update copy of Product Catalog collection

* Don't choose default active collection in polaceholder and remove highlight

* Remove inherit query option from inspector controls

* Add collection names to Product Catalog and Custom one

* Unify Collection Chooser between Modal and Placeholder

* Bring back util removed by accident

* Replace the translations domain with woocommerce

* Remove leftovers after merge

* Add pagination and no results to Product Catalog and Custom collections

* Revert textdomain change

* Fix lint error

* Add changelog entry

* Change collection label

* Bring back Inherit query from template

* Remove Custom collection and bring back single Product Collection

* Simplify applying collection

* Make sure Inherit query from template is enabled in archive templates by default and disbaled in posts/pages

* Change incorrect Playwright locator

* Add test for Product Catalog inheriting the query in product archive

* Add tests for recommendation collection hiding the predefined filters

* Add reviews to multiple products

* Update expected products in Top Rated

* Remove rating creation in test env and skip undeterministic tests

* Add skip to Best Sellers test

* Update README.md

* Add more keywords to collections, like 'product collection' to recommendation collections

* Rephrase the README note about Collections registration

* Simplify types

* Rename unchangeableFilters to hideControls

* Fix typo in file name

* Remove 'pattern' references from toolbar files

* Replace hardcoded SCSS color with wc variable

* Remove changelog file from different PR

* Move hideControls to Product Collection ayttributes

* Improve responsiveness of columns in Product Collection Placeholder

* Use admin color pallette in Product Collection Placeholder

* Move Inherit query from template to the top of Inspector Controls

* Change the Collection prefix to woocommerce rather than woocommerce-blocks

* Simplify Placeholder and Modal styles
2023-12-27 11:07:27 +01:00
..
README.md New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
best-sellers.tsx New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
featured.tsx New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
index.tsx New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
new-arrivals.tsx New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
on-sale.tsx New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
product-collection.tsx New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
top-rated.tsx New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00

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.