Skip to main content

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");

Failing to provide an idea 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.id;
const name = collection.name;
const products = collection.products;

products.forEach((product) => {
console.log(product.id, product.name);
});
info

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.

TransformCollections​

A TransformCollection is simply a grouping of pre-defined positions, rotations, and scales. Each transform in a collection has an id and a name, which are a user-defined identifier and display name respectively. See the section on Positioning Workflow Experiences for an example of how to use the transform to position a workflow experience.

const collection = bundle.getProductCollection();
const transformCollection = collection.transformCollection;

// Find the transform by id.
const transform = transformCollection.transforms.find((t) => t.id === "product-position-1");