Skip to main content

Bundles

A bundle is the foundation of every customer experience. It groups the workflow experiences (designs) a customer is working on, and gives you a set of tools for operating on transactions at scale, allowing you to set shared settings while also providing access to the underlying transactions.

Bundles are created within an Activation. When your theme is launched by Spiff Commerce, the current activation is provided on the theme context.

Creating a new bundle​

To create a bundle, you'll need to call getNewBundle on the client. This will return a bundle object, which you will use to interact with the bundle.

const bundle = await client.getNewBundle(
productCollectionId, // Optional: The product collection the customer will choose products from.
{ "my-key": "my-value" }, // Optional: Initial metadata for the bundle.
{}, // Optional: GetBundleOptions
activationId, // The activation the bundle belongs to. Available as `context.activation.id` in a theme.
);

Reloading an existing bundle​

You can retrieve the bundle ID from the bundle object. This can be used to reload the bundle at a later time.

const bundleId = bundle.getId(); // Save this somewhere.

And to reload the bundle:

const bundle = await client.getExistingBundle(bundleId);

Duplicating an existing bundle​

In order to duplicate an existing bundle, the current context must have access to it. The customer must be Authenticated and a Stakeholder of the bundle.

duplicateBundle returns a function. Call it to load the duplicated bundle.

const loadDuplicatedBundle = await client.duplicateBundle(
bundleId, // The id of the bundle to duplicate
undefined, // Optional: [boolean] Whether you wish the new duplicate to be marked as a template. Default is false
undefined, // Optional: [boolean] Whether you wish to also duplicate the transactions linked to the original bundle. Default is true.
undefined, // Optional: [GetBundleOptions] Additional options
);
const duplicatedBundle = await loadDuplicatedBundle();

Adding & Removing Workflow Experiences​

First load your workflow experiences (see Getting Started for more information). Then call addWorkflowExperiences on the bundle object, or removeWorkflowExperiences to remove them.

Always use these list-based functions, even when you only have a single workflow experience. They behave identically for one item, and fewer requests are made to the server when you pass several at once.

The user must have write access to the workflow experiences, and the bundle, in order to add them to a bundle. Only write access to the bundle is required to remove workflow experiences.

// Add workflow experiences to the bundle.
await bundle.addWorkflowExperiences([workflowExperience1, workflowExperience2]);
// Remove workflow experiences from the bundle.
await bundle.removeWorkflowExperiences([workflowExperience1, workflowExperience2]);
// Or, if you have the transactions
await bundle.removeWorkflowExperiencesByTransactions([transaction1, transaction2]);

Create the workflow experiences with getWorkflowExperiences. See Creating Workflow Experiences for more information.

Inserting Workflow Experiences​

You can also insert a workflow experience at a specific index in the bundle. This can be done by calling insertWorkflowExperience on the bundle object, and passing the index you wish to insert at. If you intend to insert the workflow experience at the end of the bundle, use addWorkflowExperiences instead.

// Insert the workflow experience at index 0.
await bundle.insertWorkflowExperience(workflowExperience, 0);

Updating Workflow Experiences​

When you have a bundle loaded, workflow experiences can be updated as normal. Access permissions will be checked against the bundle, rather than the workflow experience. See Workflow Experience for more information.

Finishing and Submitting an Order​

When the customer is ready, call finish on the bundle. This finalizes every design in the bundle and returns a BundleDesignCreationMessage. Inside a theme, pass it to SpiffThemeLoader.addToEcommerceCart().

const message = await bundle.finish((progressText) => console.log(progressText));
getSpiffThemeLoader().addToEcommerceCart(message);

If you are not using an e-commerce integration, you can place an order for every item in the bundle directly:

const order = await bundle.placeOrder();

See Order Submission for more information.

3D Preview​

Associate a bundle with a preview service to display its workflow experiences in 3D.

When you get a new bundle, this will need to be done manually after creation by calling setPreviewService on the bundle object. Calling this function on a bundle that has workflow experiences will cause all workflow experiences to be re-injected into the preview service.

If you want to eject all workflow experiences from the preview service, you can call setPreviewService with no arguments, or pass null or undefined.

note

When a bundle has a preview service associated with it, the injection and ejection of workflow experiences is handled automatically.

await bundle.setPreviewService(previewService);

You can also specify a preview service when retrieving an existing bundle.

const bundle = await client.getExistingBundle(bundleId, previewService);

Listening for hover events​

You can listen for mouse hover events on workflow experiences in the 3D preview by calling addEventListener on the bundle object, and passing a callback to the workflow-experience-hover-enter and workflow-experience-hover-exit events. The callback can be removed by calling removeEventListener with the same arguments.

This event will be a BundleEvent with the data property being a WorkflowExperienceHoverEventData object.

note

This event will only be fired when Material highlighting is enabled.

const callback = (event) => {
// Do something when the user hovers over a workflow experience.
};
bundle.addEventListener("workflow-experience-hover-enter", callback);
bundle.removeEventListener("workflow-experience-hover-enter", callback);