Integration Guide · Astro
Add Ecommerce to an Astro Website
Fetch Shoprivet product catalogs in Astro frontmatter for zero-JS HTML output, then hydrate only the interactive cart or drop in widget.js.
Prerequisites & Setup Checklist
- Astro 4+ or 5+
- Shoprivet store slug
- Sign up at shoprivet.io/app/signup, create a store, add products, and configure a payment gateway (or Cash on delivery).
Environment Variables
| Variable | Example Value | Exposure Rule |
|---|---|---|
SHOPRIVET_STORE_SLUG |
downtown-shop |
Build/SSR config |
Implementation Steps
1. Query products in Astro component frontmatter
Astro runs component frontmatter on the server or at build time, outputting pure semantic HTML and structured product markup without shipping extra client bundles.
2. Choose widget.js or a lightweight client cart island
For the fastest setup, mount <div data-shoprivet="..."> inside your shop page. For a fully bespoke Astro design, wire Add-to-Cart buttons to POST /public/stores/:slug/carts/current/items inside a small client script.
---
const API = 'https://api.shoprivet.io';
const slug = 'downtown-shop';
const res = await fetch(`${API}/public/stores/${slug}/products?page=1&limit=24`);
const { products = [] } = res.ok ? await res.json() : { products: [] };
---
<html lang="en">
<body>
<main>
<h1>Shop</h1>
<ul>
{products.map((item) => (
<li>{item.name} - {item.price} {item.currency.toUpperCase()}</li>
))}
</ul>
<div data-shoprivet={slug}></div>
<script src="https://api.shoprivet.io/widget.js" async></script>
</main>
</body>
</html>
Payment Verification, Error Handling & Security
If you pre-render static pages on Astro without SSR, trigger a rebuild webhook or use widget.js so price and stock changes reflect live without rebuilding HTML.
- Avoid placing merchant keys in Astro client scripts or PUBLIC_ environment variables.
- Always use idempotencyKey during guest cart checkout.
Deployment
Deploy statically or with Astro SSR adapters (Vercel, Netlify, Cloudflare, Node).
