woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-collection/collections
Karol Manijak f5d9b3adaa
Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209)
* Hide product grid blocks from inserter

* Expose collections in the inserter

* Arrange collections imports alphabetically and registering by usage

* Add new keywords to collections

* Update tests

* Update block references

* Add changelog

* Update docs manifest

* Fix typo in collection name in test

* MAke adjsutments and cleanup of collections keywords

* Add one more keyword

* Hide Related Products from inserter

* Replace legacy Related Products with collection when transforming classic template into block one

* Replace legacy Related Products with collection in blockified Single Product Template

* Update block references and doc manifest

* Update block references

* Update tests to reflect new collection names

* Bring back pnpm-lock to original state

* Update Related Products E2E tests

* Fix the last Related Products test

* Add default queryId to Related Products pattern

* Regenerate block references and docs manifest
2024-11-04 18:57:51 +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 Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
cross-sells.tsx Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
featured.tsx Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
hand-picked.tsx Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
index.tsx Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
new-arrivals.tsx Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
on-sale.tsx Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
product-collection.tsx Product Collection: Redesigned Collection Insertion Selection (#48911) 2024-07-09 13:53:48 +02:00
related.tsx Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
top-rated.tsx Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +01:00
upsells.tsx Hide AbstractProductGrid blocks from inserter (soft-deprecation) (#52209) 2024-11-04 18:57:51 +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.