Astro ecommerce works by pairing fast static product pages with a checkout someone else runs. The simplest option is a hosted payment link (Stripe Payment Links or a merchant-of-record service such as Lemon Squeezy, Paddle or Dodo Payments) on a “Buy” button; for a real cart, add Snipcart or the Shopify Buy Button to static pages; and for a full catalog, use Shopify’s Storefront API or an open-source backend like Medusa, with Astro rendering the storefront. Astro handles product pages, SEO and speed; the commerce platform handles payments, tax and orders.
This guide compares six ways to add ecommerce to Astro, from a single button to a headless store, with code for the common patterns.
Key Takeaways
- Astro has no built-in cart or checkout. You always pair it with a payment or commerce service.
- Payment links need no JavaScript and no adapter: a link to a hosted checkout page.
- Snipcart and the Shopify Buy Button add a cart to static HTML with a script.
- A headless store (Shopify Storefront API, Medusa) gives full control but needs more code, and often an adapter for live stock and carts.
- Merchant-of-record services handle sales tax and VAT for you, which matters for selling digital products internationally.
Astro ecommerce options compared
| Approach | Cart | Adapter needed | Catalog lives in | Effort | Best for |
|---|---|---|---|---|---|
| Payment links (Stripe, others) | No | No | Your Astro content | Lowest | One to a few products |
| Merchant-of-record checkout | Optional | No | Your content or the platform | Low | Digital products sold worldwide |
| Snipcart | Yes | No | Your Astro HTML | Low | Small and mid-sized catalogs |
| Shopify Buy Button | Yes | No | Shopify | Low | Shopify merchants adding a fast site |
| Shopify Storefront API | Yes | Optional | Shopify | High | Custom storefronts at scale |
| Open-source headless (Medusa, Saleor) | Yes | Usually | Your commerce server | Highest | Full ownership and custom logic |
1. Payment links
A payment link is a URL to a checkout page hosted by the payment provider. Create the product in Stripe (or a similar service), copy the link, and put it on the product page:
---
// src/pages/products/[id].astro
import { getCollection } from 'astro:content';
import BaseLayout from '../../layouts/BaseLayout.astro';
export async function getStaticPaths() {
const products = await getCollection('products');
return products.map((product) => ({ params: { id: product.id }, props: { product } }));
}
const { product } = Astro.props;
---
<BaseLayout title={product.data.name}>
<h1>{product.data.name}</h1>
<p>{product.data.price}</p>
<a class="buy" href={product.data.checkoutUrl}>Buy now</a>
</BaseLayout>
Keep products in a content collection with a typed schema:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const products = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/products' }),
schema: ({ image }) =>
z.object({
name: z.string(),
price: z.string(),
checkoutUrl: z.url(),
cover: image(),
}),
});
export const collections = { products };
The site stays fully static. There’s no cart, so it suits single products, courses, event tickets or donations. Stripe handles cards and receipts; you configure a success URL such as /thanks/.
2. Merchant-of-record checkouts
If you sell digital products (software, templates, downloads) to customers in many countries, sales tax and VAT become your problem with a plain payment processor. A merchant of record (MoR) sells on your behalf and handles tax collection and remittance. Lemon Squeezy, Paddle and Dodo Payments are common MoR choices; komalnakrani.com itself uses Dodo Payments for theme checkout.
Integration is usually a hosted checkout URL or an overlay script, so it works on a static Astro page exactly like a payment link. Many also send webhooks on purchase, which you handle in a serverless function or an Astro endpoint with an adapter if you need to deliver files or grant access.
3. Snipcart
Snipcart adds a full cart and checkout to any HTML page. You mark up buy buttons with data attributes, and Snipcart reads product details from them and validates prices by crawling the product URL:
---
// src/components/AddToCart.astro
interface Props {
id: string;
name: string;
price: number;
url: string;
image: string;
}
const { id, name, price, url, image } = Astro.props;
---
<button
class="snipcart-add-item"
data-item-id={id}
data-item-name={name}
data-item-price={price.toFixed(2)}
data-item-url={url}
data-item-image={image}
>
Add to cart
</button>
Load Snipcart’s script and stylesheet once in your layout, with your public API key, following its install docs. Because Snipcart validates prices against the live page, data-item-url must be the public URL of a page that contains the same button. Snipcart works well for catalogs of tens to a few hundred products managed in Markdown or a CMS.
4. Shopify Buy Button
If the store already runs on Shopify, the Buy Button sales channel generates an embed snippet for a product or collection. Paste it into an Astro component and you get Shopify’s cart and checkout on your fast Astro pages. Inventory, orders and payments stay in Shopify admin.
It’s the quickest way to put Shopify products on a content-led Astro site, such as a brand blog or a landing page. Styling options are limited to what the Buy Button configurator offers, since the widget renders in an iframe.
5. Shopify Storefront API (headless Shopify)
For a fully custom storefront, query Shopify’s Storefront GraphQL API. At build time you can generate product pages; carts are created through the API from the browser or a server route:
// src/lib/shopify.ts
const endpoint = `https://${import.meta.env.SHOPIFY_STORE_DOMAIN}/api/2025-01/graphql.json`;
export async function shopify<T>(query: string, variables: Record<string, unknown> = {}): Promise<T> {
const res = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Storefront-Access-Token': import.meta.env.SHOPIFY_STOREFRONT_TOKEN,
},
body: JSON.stringify({ query, variables }),
});
const json = await res.json();
if (json.errors) throw new Error(JSON.stringify(json.errors));
return json.data;
}
export async function getProducts() {
const data = await shopify<{ products: { nodes: { handle: string; title: string }[] } }>(`
query { products(first: 50) { nodes { handle title } } }
`);
return data.products.nodes;
}
Use a current API version from Shopify’s docs; versions are dated and retire on a schedule. Static product pages are fast and crawlable, but prices and stock are frozen at build time. For live inventory, render product pages on demand with an adapter and Astro 7’s cache and routeRules, or fetch stock client-side in a small island. A custom content loader can also bring Shopify products into a content collection.
6. Open-source headless commerce
Medusa and Saleor are open-source commerce backends you host yourself. They give you products, carts, orders, discounts and payment provider integrations through an API, and Astro builds the storefront. Choose this when you need custom pricing logic, B2B rules, marketplace features or full ownership of the data, and you have the engineering time to run a backend.
Cart state across pages
With Snipcart or the Shopify Buy Button, the vendor script manages the cart. For a custom cart, keep state in a small store shared between islands, persisted to localStorage:
// src/stores/cart.ts
import { persistentAtom } from '@nanostores/persistent';
export type CartItem = { id: string; qty: number };
export const cart = persistentAtom<CartItem[]>('cart', [], {
encode: JSON.stringify,
decode: JSON.parse,
});
A cart badge island in the header and an add-to-cart island on product pages both read the same store. Our guide to React components in Astro shows the island side.
SEO for Astro stores
Astro’s static product pages are its biggest ecommerce advantage: complete HTML that loads quickly and can be indexed without JavaScript. Make the most of it:
- Add
ProductJSON-LD with price, availability and images; see JSON-LD structured data in Astro. - Use
<Image />fromastro:assetsfor product photos, with explicit sizes. - Give every product a unique title and description.
- Keep prices in structured data in sync with the checkout. A rebuild on price change, triggered by a webhook, handles this for static pages.
Choosing an Astro ecommerce approach
- One to five products: payment links, or a merchant-of-record checkout for digital goods.
- A small catalog with a cart, no backend: Snipcart.
- Already on Shopify: Buy Button for speed, Storefront API for a custom storefront.
- Large catalog, custom logic, in-house engineers: headless Medusa or Saleor.
Komal has retail and e-commerce Astro themes with product and collection page layouts that you can connect to any of these checkouts, delivered as static Astro 7 projects. For the official overview, see Astro’s e-commerce guide.
FAQ
Can you build an ecommerce site with Astro?
Yes. Astro renders fast product and collection pages, and a commerce service handles the cart, checkout and payments. Options range from payment links and Snipcart on a static site to a headless Shopify or Medusa storefront.
Does Shopify work with Astro?
Yes, in two ways. The Shopify Buy Button embeds products and a cart in Astro pages with a script, and the Storefront API lets you build a fully custom storefront that fetches products and creates carts.
Do I need SSR for an Astro store?
Not for most small stores. Payment links, Snipcart and the Shopify Buy Button all work on static pages. You need an adapter for live stock on product pages, custom cart APIs, customer accounts or webhook handling inside Astro.
How do I add a shopping cart to a static Astro site?
Use a cart service such as Snipcart or the Shopify Buy Button, which runs from a script on static pages. For a custom cart, store items in a shared client-side store like nanostores and send the cart to your payment provider’s checkout API.
What is a merchant of record and do I need one?
A merchant of record sells your product on your behalf and takes responsibility for collecting and paying sales tax and VAT. It’s most useful for digital products sold to customers in many countries, where tax rules are complex.