Shopify Hydrogen - Combined Checkout

This guide will walk you through Purple Dot's Platform integration into any Shopify Hydrogen Storefront.

Combined checkout overview

The Combined Checkout flow uses your store’s normal Shopify cart, unlike the Express flow, which uses Purple Dot’s own cart. This means that pre-order and in-stock items coexist within the same Shopify cart, and Purple Dot’s integration layers on top of your existing cart implementation to manage pre-order metadata and checkout routing.

There are 5 key requirements an integration needs to implement for a Combined Checkout:

  • Displaying pre-order items. Purple Dot is the source of data for which items are on pre-order and their estimated ship dates. The integration needs to show that those items are on pre-order, with the estimated ship dates, the "Learn more” informational content, and a “Pre-order” call to action.

  • Adding pre-order items to cart. When adding an item to the cart, the integration needs to determine if it is a pre-order and attach the waitlist ID and ship dates if it is.

  • Showing pre-order items in cart. When a pre-order item is in the cart, the estimated ship dates need to be displayed.

  • Using the Combined pre-order checkout. The Purple Dot pre-order checkout lets shoppers checkout with pre-order items. When a pre-order item is in the cart, the integration needs to direct the shopper to the Purple Dot pre-order checkout instead of the Shopify checkout.

  • Shopper portal. The shopper self-service portal lets shoppers manage their pre-orders. The integration needs to be embedded on a page in the storefront that the shoppers will be directed to in their confirmation email.

Install the Purple Dot browser package

npm install @purple-dot/browser

Setup vite config

If you're using vite in your hydrogen storefront, update the vite.config.ts file with the following:

export default defineConfig({
  plugins: [
    // ...
  ],
  build: {
    // ...
  },
  ssr: {
    optimizeDeps: {
      include: [
        '@purple-dot/browser/*'],
      ],
    },
  },
});

Add config variables

In your .env file and in remix.env.d.ts, add PURPLE_DOT_API_KEY and set it to the public API key you can find in the integration page of your Purple Dot merchant portal. You must also have PUBLIC_STOREFRONT_API_TOKEN and PUBLIC_STORE_DOMAIN set.

Initialise the package

Before you can use the package, it needs to be initialised with your store's apiKey and the Storefront cart adapter. This needs to be initialised on each loader that requires the use of the package so that you can use the package in your backend handlers as well as React components:

Set up product pages

On every product form, two elements are expected if a variant/product is on preorder:

  1. The waitlist shipping dates so that shoppers know when to expect their order to start shipping

  2. A Purple Dot learn more element so that shoppers can understand their preorder process with Purple Dot

A non-preorder product:

A pre-order product:

In the following example, we are going to fetch the preorder data in the loader:

Then display the preorder information on the product form if the variant is on pre-order:

Set the right line item properties when adding to cart

The Purple Dot package expects the __releaseId property to exist on the line item to detect preorders in the shopper’s cart. You can easily add this by modifying your add to cart calls. Here’s how you can do it using the standard AddToCartButton element.

Display preorder shipping date in your side cart

You can use the Purple Dot Preorder property that you added in your line item to differentiate preorder items in the side cart. For example, with a CartLineItem.tsx file that contains the component to display each line item in the shoppers, here’s how you can do it:

Open the Purple Dot checkout

Once the shoppers have added their preorder items to the cart, it’s time to let them checkout through the Purple Dot checkout. You can do this on the cart page as shown below:

This opens up an iframe that allows the shopper to checkout with Purple Dot.

Embed the Purple Dot self-service for shoppers to manage their preorders

Pick any page where you’d like to display the Purple Dot self-service and embed the Purple Dot self-service as shown below:

Add the URL of this page to the Cancel link within Settings > Email in the merchant portal.

Last updated