Product Collections
Product collections provide a mechanism for grouping together products in a way that is meaningful to your business. For example, you might want to group together all products that are on sale, or all products that are made from a particular material or all products that are available to be added into the cart together.
Associating a collection to a bundle
Collections are associated with a bundle by providing the collection id when constructing the bundle.
const bundle = await client.getNewBundle(
"1234-5678-9012-3456", // The product collection ID
undefined,
{},
activationId, // The activation the bundle belongs to
);
Failing to provide an ID here will result in the bundle not being able to retrieve a collection in the following step.
Retrieving product collections
Product collections are retrieved from the Spiff API using the getProductCollection method on the bundle. This method returns a ProductCollection object or undefined if no collection is available.
const collection = bundle.getProductCollection();
const id = collection?.getId();
const name = collection?.getName();
const products = collection?.getProducts() ?? [];
products.forEach((product) => {
console.log(product.getId(), product.getName());
});
When used with bundles, collections act as a way of restricting the products that can be added to the cart. It's important to remember that when a collection is provided, adding transactions for a product that doesn't belong to that collection will result in an exception being generated.
Associated entities
To ease the process of working with collections, some extra entities can be associated with a product collection:
GlobalPropertyConfiguration
Global properties allow you to apply values across all transactions in a bundle. Each workflow is configured to handle where these properties are applied. See the page on Global Properties for more information.