Connect to Shopify

How to wire the Add to Cart and Buy Now buttons in index.html to your Shopify store via the Storefront API.

What you need before starting:
① A Shopify store (any plan)
② The Colostrum Capsules product already in your Shopify store (Supliful pushes it automatically once you connect your store in the Supliful dashboard)
③ About 15 minutes

Step 1 Connect Supliful to Shopify

If you haven't done this yet, do it first — Supliful will push the product to your store.

  1. Log in to app.supliful.comMy StoresConnect store
  2. Choose Shopify and enter your store URL (e.g. your-store.myshopify.com)
  3. Approve the permissions in the Shopify OAuth flow
  4. Back in Supliful, go to My Products → Colostrum Capsules → click Push to store

Once pushed, the product will appear in your Shopify Admin under Products.

Step 2 Create a Storefront API Access Token

This is a public read-only token your HTML page uses to talk to Shopify. It is safe to put in client-side code.

  1. In your Shopify Admin, go to Settings → Apps and sales channels → Develop apps
  2. Click Create an app → name it Website Storefront → click Create app
  3. Click the Configuration tab → under Storefront API access scopes, enable:
    • unauthenticated_read_product_listings
    • unauthenticated_write_checkouts
  4. Click Save → click the API credentials tab → click Install app
  5. Copy the Storefront API access token — you'll need it in Step 4
The Storefront API token starts with a long random string. It is not the same as the Admin API key — make sure you copy the one labelled "Storefront API access token".

Step 3 Get Your Product's Variant ID

Shopify uses a Global ID (GID) to identify each product variant. You need this to add items to the cart.

  1. In Shopify Admin → Products → click Colostrum Capsules
  2. Scroll to the Variants section — since there's only one variant, click it
  3. Look at the URL in your browser — it ends in a number, e.g. /variants/12345678901
  4. Your GID is: gid://shopify/ProductVariant/12345678901
    (replace the number with yours)

Alternatively, run this in your browser console after loading the Shopify Admin products page to list all variant IDs — but the URL method above is the quickest.

Step 4 Edit index.html — Add Your Credentials

Open index.html in a text editor. Find the <script> block near the bottom. Replace the existing addToCart() function with the code below.

First, add these three lines at the very top of the <script> block:

/* ── Shopify credentials — fill these in ── */
const SHOPIFY_DOMAIN = 'your-store.myshopify.com';      // ← your store URL
const SHOPIFY_TOKEN  = 'your_storefront_access_token';  // ← from Step 2
const VARIANT_GID    = 'gid://shopify/ProductVariant/12345678901'; // ← from Step 3

Then replace the existing addToCart() function entirely with this:

/* ── Add to Cart → Shopify Storefront API ── */
async function addToCart() {
  const qty = parseInt(document.getElementById('qty').value) || 1;

  // Visual feedback while loading
  const btn = document.getElementById('atc-btn');
  const origHTML = btn.innerHTML;
  btn.innerHTML = 'Loading…';
  btn.style.opacity = '0.7';
  btn.disabled = true;

  try {
    const res = await fetch(
      `https://${SHOPIFY_DOMAIN}/api/2024-01/graphql.json`,
      {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'X-Shopify-Storefront-Access-Token': SHOPIFY_TOKEN,
        },
        body: JSON.stringify({
          query: `
            mutation cartCreate($input: CartInput!) {
              cartCreate(input: $input) {
                cart { checkoutUrl }
                userErrors { field message }
              }
            }
          `,
          variables: {
            input: {
              lines: [{ merchandiseId: VARIANT_GID, quantity: qty }]
            }
          }
        })
      }
    );

    const json = await res.json();
    const errors = json?.data?.cartCreate?.userErrors;
    const checkoutUrl = json?.data?.cartCreate?.cart?.checkoutUrl;

    if (errors?.length) {
      console.error('Shopify error:', errors);
      alert('Could not add to cart. Please try again.');
      btn.innerHTML = origHTML;
      btn.style.opacity = '';
      btn.disabled = false;
      return;
    }

    // Update cart count badge
    cartCount++;
    const dot = document.getElementById('cart-count');
    dot.textContent = cartCount;
    dot.style.display = 'flex';

    // Show success then redirect to Shopify checkout
    btn.innerHTML = '✓ Added!';
    btn.style.background = '#8A3E08';
    btn.style.opacity = '';
    btn.disabled = false;
    setTimeout(() => { window.location.href = checkoutUrl; }, 800);

  } catch (err) {
    console.error(err);
    alert('Network error. Please try again.');
    btn.innerHTML = origHTML;
    btn.style.opacity = '';
    btn.disabled = false;
  }
}
Important: The SHOPIFY_DOMAIN must be your .myshopify.com URL, not your custom domain (e.g. my-shop.myshopify.com, not www.mybrand.com). The Storefront API endpoint only accepts the .myshopify.com domain.

Step 5 Add Your Product Image

Find this comment block in index.html:

<!--
  REPLACE: add your product image here
  <img src="your-product-image.png" alt="Colostrum Capsules 500mg bottle" />
-->

Download your labelled product image from the Supliful mockup tool (or upload your own PNG), then replace the entire <div class="gallery-placeholder">…</div> block with:

<img src="colostrum.png" alt="Colostrum Capsules 500mg bottle"
     style="width:100%; height:100%; object-fit:contain;" />

Place your image file in the same folder as index.html.

Step 6 Update Brand Name & Prices

  1. Search VitaPure in index.html and replace with your brand name (appears 3 times — nav, footer, page title)
  2. The price is shown as $39.95 and the "was" price as $57.00 — update if different. Search for both values.
  3. Update the <title> tag at the top of the file with your brand name

Step 7 Test Locally

Open index.html directly in Chrome or Firefox. Click Add to Cart — you should be redirected to your Shopify checkout with 1× Colostrum Capsules in the cart.

CORS issue? If the page is opened as a local file (file:///), some browsers block the API call. Use a simple local server instead:
npx serve . (requires Node) or open via VS Code Live Server extension. Alternatively, just deploy first and test on the live URL.

Step 8 Deploy

Option A — Netlify (recommended, free)

  1. Go to app.netlify.comAdd new site → Deploy manually
  2. Drag and drop the entire colostrum-capsules/ folder onto the page
  3. Netlify gives you a live URL instantly (e.g. amazing-name-123.netlify.app)
  4. Optional: connect a custom domain under Site settings → Domain management

Option B — Shopify as a Page (no external hosting needed)

  1. In Shopify Admin → Online Store → Themes → Edit code
  2. Under Templates, click Add a new template → choose page → name it page.landing → click Create template
  3. Delete all default content and paste the full contents of index.html (including <!DOCTYPE html> through </html>)
  4. Click Save
  5. Go to Online Store → Pages → Add page → set the title → under Template, select page.landing → Save
  6. Your page is now live at your-store.myshopify.com/pages/colostrum-capsules
When hosting on Shopify itself, the Shopify checkout redirect will work seamlessly since you're already on the same domain ecosystem.
You're live! The Add to Cart and Buy Now buttons now create a real Shopify checkout. Supliful receives the order automatically and handles fulfilment. You keep the margin between your $39.95 retail price and Supliful's $10.45 cost.

Quick Reference

What Where to find it
Store domainShopify Admin URL bar — your-store.myshopify.com
Storefront API tokenSettings → Apps → Develop apps → your app → API credentials
Variant GIDAdmin → Products → Colostrum Capsules → variant URL → last number → wrap in gid://shopify/ProductVariant/
Storefront API docsshopify.dev/docs/api/storefront