> For the complete documentation index, see [llms.txt](https://docs.getpurpledot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.getpurpledot.com/e-commerce-platforms/shopify/integrate-with-a-headless-storefront/combined-checkout.md). Agents can also search and read this documentation through its [MCP server](https://docs.getpurpledot.com/~gitbook/mcp).

# Set up combined checkout for a headless storefront

Show pre-order state, attach waitlist line attributes, and open combined checkout from a headless Shopify cart.

Combined checkout uses the Shopify cart. See [Combined cart](https://docs.getpurpledot.com/understanding-purple-dot/choosing-a-checkout-method.md#combined-cart).

## Before you start

* `@purple-dot/browser` is installed and you have the public API key. See [Integrate with a headless storefront](https://docs.getpurpledot.com/e-commerce-platforms/shopify/integrate-with-a-headless-storefront.md).
* The storefront uses the Shopify AJAX cart or the Storefront API cart.

## Steps

1. Initialize the package with the cart adapter that matches the cart.

AJAX cart:

```js
import * as PurpleDot from '@purple-dot/browser';
import { ShopifyAJAXCart } from '@purple-dot/browser/shopify-ajax-cart';

PurpleDot.init({
  apiKey: 'YOUR_PUBLIC_API_KEY',
  cartAdapter: new ShopifyAJAXCart(),
});
```

Storefront API cart. The first argument is the shop domain, such as `your-store.myshopify.com`. The second is the Storefront API public access token.

```js
import * as PurpleDot from '@purple-dot/browser';
import { ShopifyStorefrontCart } from '@purple-dot/browser/shopify-storefront-cart';

PurpleDot.init({
  apiKey: 'YOUR_PUBLIC_API_KEY',
  cartAdapter: new ShopifyStorefrontCart(
    'your-store.myshopify.com',
    'STOREFRONT_PUBLIC_ACCESS_TOKEN'
  ),
});
```

2. On a product page, read the selected variant. On a collection page, read the product by handle:

```js
import * as api from '@purple-dot/browser/api';

const variant = await api.fetchVariantsPreorderState(variantId);
const product = await api.fetchProductsPreorderState(productHandle);
```

`state` is one of `NO_OPEN_WAITLISTS`, `AVAILABLE_IN_STOCK`, `ON_PREORDER`, or `SOLD_OUT`. For `ON_PREORDER`, label the button **Pre-order**, show `waitlist.display_dispatch_date`, and render `<purple-dot-learn-more />`. For `SOLD_OUT`, disable the button. For `AVAILABLE_IN_STOCK` and `NO_OPEN_WAITLISTS`, leave the normal add-to-cart control.

If the store uses [location-aware waitlists](https://docs.getpurpledot.com/understanding-purple-dot/inventory-and-virtual-locations.md#location-aware-waitlists), pass the shopper's country code as the second argument to either call, such as `fetchVariantsPreorderState(variantId, 'GB')`. See [Show pre-order state on a product page](https://docs.getpurpledot.com/e-commerce-platforms/other-and-custom/show-pre-order-state-on-a-product-page.md).

3. When the variant is `ON_PREORDER`, add the line with attributes from `purpleDotAttributes`. Pass `isPreorder`, `releaseId` (`waitlist.id`), `estimatedShipDates` (`waitlist.display_dispatch_date`), and `sellingPlanId` and `compatibleCheckouts` when the response includes them.

```js
import { purpleDotAttributes } from '@purple-dot/browser/cart';

const attributes = purpleDotAttributes({
  isPreorder: true,
  releaseId: variant.waitlist.id,
  estimatedShipDates: variant.waitlist.display_dispatch_date,
  sellingPlanId: variant.waitlist.selling_plan_id,
  compatibleCheckouts: variant.waitlist.compatible_checkouts,
});
```

The helper sets `__releaseId` to the waitlist id. When the waitlist has no Shopify selling plan, it also sets `Purple Dot Pre-order` to the ship-date text. Show that attribute in the cart when it is present.

For an AJAX cart, you can intercept cart requests instead of setting the attributes at each add-to-cart call:

```js
import * as interceptors from '@purple-dot/browser/shopify-ajax-interceptors';

interceptors.start();
```

4. If the cart contains a pre-order, open the Purple Dot checkout instead of Shopify checkout.

```js
import * as checkout from '@purple-dot/browser/checkout';
import { cartHasPreorderItem } from '@purple-dot/browser/cart';

if (await cartHasPreorderItem()) {
  await checkout.open();
}
```

`cartHasPreorderItem()` with no argument reads the cart through the adapter. Pass line items when you already have them. For a Storefront API cart, pass the cart id to `checkout.open({ cartId })`.

5. On the shopper page, render `<purple-dot-self-service />`. Set **Cancel link** under **Settings** > **Email** to that page. See [Customize shopper emails](https://docs.getpurpledot.com/set-up-and-launch/checkout-and-shopper-experience/customize-shopper-emails.md).

## Verify

Add a pre-order variant. The cart line includes `__releaseId`. Checkout opens the Purple Dot checkout, and an in-stock-only cart still uses Shopify checkout.

## Troubleshooting

* [The pre-order button is not showing](https://docs.getpurpledot.com/troubleshooting/storefront-and-checkout/pre-order-button-is-not-showing.md)

## Related

* **Concept:** [Combined cart](https://docs.getpurpledot.com/understanding-purple-dot/choosing-a-checkout-method.md#combined-cart)
* **Do this:** [Integrate with a headless storefront](https://docs.getpurpledot.com/e-commerce-platforms/shopify/integrate-with-a-headless-storefront.md)
* **Look up:** [Public API](https://docs.getpurpledot.com/purple-dot-apis/public-api.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.getpurpledot.com/e-commerce-platforms/shopify/integrate-with-a-headless-storefront/combined-checkout.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
