Skip to content

Quickstart ​

Put your shop's products on a page, add one to a cart and send the shopper to checkout. It takes about ten minutes.

You need an Eldra organisation with a few products, and Node 22 or newer.

1. Create a Vue app ​

bash
pnpm create vite my-shop --template vue-ts
cd my-shop
pnpm add @eldrajs/sdk @eldrajs/ui

2. Let your app talk to Eldra ​

In Studio:

  1. Go to Settings → API & tracking and copy the Organization ID.
  2. Go to Settings → General → Site addresses. Under Other sites, add http://localhost:5173, where Vite serves your app.

There is no API key: everything a storefront reads is public, from any address. Adding to a cart and ordering only work from addresses you registered, so a stranger's page cannot spend in your shop.

Put the id in a .env file at the root of the app:

bash
VITE_ELDRA_ORG_ID=your-organisation-id

3. Create the client ​

Make src/eldra.ts:

ts
import { createCartSession, createEldraClient } from '@eldrajs/sdk';

export const eldra = createEldraClient({ orgId: import.meta.env.VITE_ELDRA_ORG_ID });

// Remembers the shopper's cart between visits.
export const cartSession = createCartSession();

Create the client once and import it wherever you need it.

4. Show your products ​

Replace src/App.vue:

vue
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { ProductCard, toMinorUnits } from '@eldrajs/ui';
import '@eldrajs/ui/style.css';
import { eldra } from './eldra';

type Product = { id: string; slug: string; title: string; minPrice: number };

const products = ref<Product[]>([]);

onMounted(async () => {
  const result = await eldra.catalog.listProducts<{ data: Product[] | null }>();
  products.value = result.data ?? [];
});
</script>

<template>
  <main class="grid">
    <ProductCard
      v-for="product in products"
      :key="product.id"
      :product="{
        title: product.title,
        url: `/products/${product.slug}`,
        price: { amount: toMinorUnits(product.minPrice, 'ISK') },
      }"
      currency="ISK"
      locale="is-IS"
    />
  </main>
</template>

<style>
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px;
  padding: 24px;
}
</style>

Run pnpm dev and open http://localhost:5173. You should see a card for each product.

Two ways of writing a price

The API sends prices as plain numbers: 179.9 is 179,90 €. ProductCard and Price take the currency's smallest unit instead (17990 cents), so convert with toMinorUnits. Krónur have no smaller unit, so for ISK the number stays the same. Set currency to your shop's currency.

5. Add to cart and check out ​

Turn on the card's add button and handle it:

vue
<script setup lang="ts">
// …the imports and product list from step 4, plus:
import { cartSession } from './eldra';

async function addToCart(product: Product) {
  // A product can have several variants (sizes, colours). Take the first one here.
  const detail = await eldra.catalog.getProduct<{ variants: { id: string }[] }>(product.id);

  const cart = (await eldra.cart.addItem({
    cartId: cartSession.read() ?? undefined,
    productId: product.id,
    variantId: detail.variants[0].id,
    quantity: 1,
  })) as { id: string };
  cartSession.remember(cart.id);
}

async function checkOut() {
  const cartId = cartSession.read();
  if (cartId) window.location.href = await eldra.checkout.url({ cartId, locale: 'is-IS' });
}
</script>
vue
<ProductCard
  v-for="product in products"
  :key="product.id"
  :product="{
    title: product.title,
    url: `/products/${product.slug}`,
    price: { amount: toMinorUnits(product.minPrice, 'ISK') },
  }"
  currency="ISK"
  locale="is-IS"
  quick-add
  @quick-add="addToCart(product)"
/>

<Button variant="primary" @click="checkOut">Check out</Button>

Import Button from @eldrajs/ui beside ProductCard.

The as casts name the fields this page reads. Once you add the Vite plugin (Getting started), every response is typed for you.

Click Add to cart on a card, then Check out. You land on Eldra's hosted checkout with your cart. Payment, delivery and the receipt all happen there.

Next ​

  • Getting started: typed responses, staging, preview and errors.
  • Components: everything @eldrajs/ui gives you, with live examples.
  • Images: show product photos at the right size.
  • Themes: build a site whose pages merchants edit in Studio.

Eldra