woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-collection/collections
Karol Manijak 5b420159cb
Product Collection: disable "Sync with current query" option for 2nd+ block on archive (#44577)
* Refactor store usage

* Prepare function resolving inherit property for additional check

* Add logic to disable sync with query if there's already one Product Collection on archive that does that

* Add changelog

* Cover the post editor case

* Add E2E test for that and small refactor in tests

* Remove duplicated import

* Fix lint problems

* Fix typo in test description

Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>

* Replace confusin abbreviation with other description

* Update the logic to be more robust and covering also the case where Product Collection blocks are nested

* Add issue reference to the comment

* Add eslint disable before ts-ignore

---------

Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>
2024-02-19 17:51:42 +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 Product Collection: Make sure all variations are taken into account when choosing collection (#43273) 2024-01-08 10:55:42 +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 Product Collection: disable "Sync with current query" option for 2nd+ block on archive (#44577) 2024-02-19 17:51:42 +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.