Sell from a Content site with the storefront kit
The storefront kit puts a shop on a Content site: a list of products by category with search and sort, an address for every active product with a gallery, a price, options and stock, and, from kit version 1.1.0, a buy button, a cart, a pay form and an order confirmation. It builds on the starter kit and reads your products from Commerce in the browser. The shopper pays on your payment provider’s page, so your site never handles card details.
How it fits together
Section titled “How it fits together”| Piece | Where it lives | What it does |
|---|---|---|
| The kit’s Contracts and Templates | Your Content organization | Describe a product list, a card, a hero, a price, a variant picker, availability, a detail section, a buy button, a cart and an order confirmation |
| A shop experience on a parameter node | Content | One page whose last address segment is a product key: /shop/products/ash-break-cue |
@ebitex/commerce-kit-react |
Your site | Draws those sections, reads price and stock from Commerce, and keeps the cart |
| A Commerce delivery key | Your site | Lets the browser read the catalogue and, with two switches on, run a cart and read the shopper’s own order |
Price, availability and every total always come from Commerce when the page is drawn, never from what Content saved, so a change in Commerce shows with no publish. A variant with no price shows no price, never zero, and cannot be bought.
What you need
Section titled “What you need”- The starter kit installed, with its demo site if you want the storefront’s demo.
- Assets connected to Content, and Commerce connected to Content with a delivery key for the store whose products you will show. See Reading the Commerce catalogue.
- Two browser-safe delivery keys, one for Content and one for Commerce, each restricted to the origins your site runs on. The Commerce key must read the same store the Content site’s Commerce connection points at, and needs Allow carts and checkout and Allow reading orders switched on to sell.
- A store with a payment provider connected. A store in test mode sells with test payments and says so on the cart and the confirmation.
- Optional: an Audience key and the visitors SDK, if your site asks shoppers to be recognised. Selling works without either.
Install the kit
Section titled “Install the kit”In Content, open Tools → Starter kits, choose the storefront kit and read the preview. It tells you, with
what to do for each, if the starter kit, Assets or Commerce is missing. Leave the demo on to get a working shop
beneath the starter kit’s demo site: shop, shop/products, shop/products/{key}, shop/cart and
shop/order. Then publish the demo’s root.
The demo adds no products. It lists the products your own store holds.
Before it shows up
Section titled “Before it shows up”Installing adds drafts and publishes nothing. Before the shop looks right:
- Publish the demo’s root, then the
shopsubtree beneath it: publishing the root does not publish its child nodes, so the shop, product, cart and order pages are each published with it. - Publish the Component
ebitex-storefront. It is in no page, so publishing a page does not publish it. Your site fetches it by id for the product address, the cart and order addresses, and the labels. After installing kit 1.1.0, publish it again: it now carries two more links. - Publish the starter kit’s
ebitex-site-chrometoo. It is in no page either, and without it the header, and the header’s cart button, does not render at all. - Make the product pictures public in Assets. An uploaded item is private until you do.
If you do not, the page still draws, but product cards have no link (Delivery answers 404 not_published for the Component) and a picture whose Assets item is private is an empty tile. A shop with no cart link on the holder sends the shopper back to the page they paid from, and a pay form with no order-confirmation link says it cannot send the shopper back. In development the provider says so once per cause in the browser console, and says nothing in production:
@ebitex/commerce-kit-react: the storefront holder is not published, so product cards are drawn without a link and with the English labels. Publish the Component 'ebitex-storefront'.@ebitex/commerce-kit-react: a product image could not be read because its Assets item is not public, so its card shows an empty tile. Make the Assets item public.If your organization already holds kit 1.0.0
Section titled “If your organization already holds kit 1.0.0”An install never changes an item you already hold, so 1.1.0 over 1.0.0 adds the new items (the category group, the three Contracts with their Templates and settings Contracts, the demo’s cart and order Components and nodes) and leaves your own copies of four items as they are. Only test organizations hold 1.0.0. To sell there, make these five edits by hand:
- On
ebitex-product-hero, allowebitex-buy-button-templatein thecontentfield. - On
ebitex-shop-experience, allowebitex-buy-button-template,ebitex-cart-templateandebitex-order-confirmation-templatein thesectionsfield. - On
ebitex-storefront, add two link fields,cartandorder-confirmation, and point each at the experience nodeshop/cartorshop/order, not at the Component that holds the presentation. - On
ebitex-store-labels, add the thirty-eight new fields astext, localizable, not mandatory. A new field cannot use the deprecatedshortTexttype. An empty one falls back to the renderer’s English. - On the demo product experience you keep, add the buy button Template to the hero’s
content. The demo is not changed by an install over 1.0.0 either, so that page has no buy button until you do.
Do step 2 before you install the demo again, or install without the demo. The demo’s cart and order
Components put the new Templates in sections; until your shop experience allows them the whole demo is refused
with a validation error and nothing is written. The demo is chosen when you install: after an install without it
the screen says everything is already here and does not offer it again. If you installed without it, make the
edits above and install again with the demo on.
Draw the shop
Section titled “Draw the shop”npm install @ebitex/content-sdk @ebitex/commerce-sdk @ebitex/starter-kit-react @ebitex/commerce-kit-reactImport both packages’ tokens after Tailwind, and let Tailwind see their classes:
@import "tailwindcss";@import "@ebitex/starter-kit-react/styles.css";@import "@ebitex/commerce-kit-react/styles.css";@source "../node_modules/@ebitex/starter-kit-react/dist";@source "../node_modules/@ebitex/commerce-kit-react/dist";import { createCommerceClient } from '@ebitex/commerce-sdk'import { createContentClient } from '@ebitex/content-sdk'import { ContentProvider, Experience } from '@ebitex/content-sdk/react'import { EbitexMarkdown, EbitexProvider, ebitexRenderers } from '@ebitex/starter-kit-react/react'import { createProductData, localStorageAdapter } from '@ebitex/commerce-kit-react'import { CommerceProvider, commerceRenderers } from '@ebitex/commerce-kit-react/react'
// Two browser-safe delivery keys, each restricted to the origins this site runs on: one for Content, one for Commerce. They must read the same store the Content site's// Commerce registration points at.const content = createContentClient({ apiKey: 'your-content-browser-safe-key' })const commerce = createCommerceClient({ apiKey: 'your-commerce-browser-safe-key' })
// The loader for the product address (`/shop/products/{key}`): one Commerce read serves every section on the page, and an unknown key draws the site's not-found.// Make it once, outside your components, so it is the same object on every render.const productData = createProductData(commerce)
// Where the cart token and the pending order are kept. `localStorage` by default; `cookieAdapter()` lets a server-rendering host read them.const cart = { storage: localStorageAdapter() }
export function Shop({ pathname }: { pathname: string }) { return ( <EbitexProvider client={content}> {/* `cart` turns selling on: a buy button, the header's cart, the cart page, the pay form and the confirmation. Leave it out for a catalogue only. */} <CommerceProvider commerce={commerce} content={content} productData={productData} cart={cart}> <ContentProvider client={content} renderers={{ ...ebitexRenderers(), ...commerceRenderers() }} markdown={EbitexMarkdown}> {/* One catch-all: Content resolves `/shop/products/trail-runner` to the parameterised node and hands the key over. */} <Experience path={pathname} routeData={[productData]} notFound={<p>Page not found.</p>} /> </ContentProvider> </CommerceProvider> </EbitexProvider> )}createProductData(commerce) makes the loader for the product address. Create it once, outside your
components, so it is the same object on every render. A key that names no product draws your site’s
not-found; a product pinned on a section that no longer exists draws nothing for that one section.
The host keeps its single catch-all <Experience>: Content resolves /shop/products/ash-break-cue to the
parameter node and hands over { key: 'ash-break-cue' }. The cart and the confirmation are ordinary pages
(/shop/cart, /shop/order), so the same catch-all draws them.
Which product a section shows
Section titled “Which product a section shows”A section with a product chosen shows that product, on any experience. A section with none shows the product the address names. With neither, it draws nothing and, in development, says so.
Selling
Section titled “Selling”Give CommerceProvider a cart prop and selling is on. Leave it off and the package draws no cart, reads no
storage and makes no cart request.
No cart until the first add. A shopper who only browses writes nothing and creates nothing. The first add
creates a cart; Commerce answers a cart token, once, which is a secret for that one cart. The package keeps
it and sends it as X-Cart-Token to the Commerce cart and order routes, and to nowhere else.
The buy button
Section titled “The buy button”Put the ebitex-buy-button-template section in a product hero or anywhere. It adds the variant the shopper
chose, with a quantity when show-quantity is on, and it is disabled with “Choose an option” until every option
axis has a value and with “Sold out” for an out-of-stock variant that is not on backorder. An addition is
announced politely. After adding it opens the cart drawer or stays put, as the section’s after-add setting says.
The header cart
Section titled “The header cart”commerceRenderers() also returns ebitex-site-header-template: the starter’s header with a cart button in its
right-hand cluster. The button’s accessible name carries the count (“Cart, 3 in cart”) and it opens a drawer, a
modal dialog with focus held inside, closed by Escape, and returning focus to the button. Leave that one entry
out of the renderer map to have no header cart, or place <CartButton /> in your own header. The drawer shows
the lines and totals and links to the cart page; when the holder has no cart link it carries the pay form itself.
The cart and the pay form
Section titled “The cart and the pay form”The ebitex-cart-template section lists the lines with named quantity controls and a remove button, and shows the
server’s totals. A line Commerce says is unavailable or unpriced stays visible with a remove control and blocks
paying. A store whose prices exclude tax shows no tax and no total, never zero, until a country is given.
The pay form collects an email, a name, a country, a region and a postcode, and, when something in the cart
ships, the recipient, two address lines, the city and a phone number. A digital-only cart asks for none of
those. Every field has a visible label and the right autocomplete value; each refusal (a missing field,
address_required, shipping_unavailable, payments_not_configured, a rate limit with its wait) is shown beside
the field it concerns, tied to it with aria-describedby, and the first takes focus. A test-mode store is marked
as a test order on this step.
On submit the form sets the address, starts the checkout with a return address and a cancel address built from the holder’s links on your site’s origin, writes the pending order, and sends the browser to the payment provider’s page. Neither address carries an order id or a token. A declined or abandoned payment returns to the cart, intact.
The delivery address is personal data. It is typed into the form and posted to Commerce. The package never writes it, your shopper’s email or name to the device. Commerce returns it on the cart view to the holder of that cart’s token, so the shopper’s own form can be filled in again, and to nobody else; the cart is deleted when it is paid. No order read, delivery key, webhook, management key, search, dashboard, log or the Activity Log returns it, and Commerce shows an order’s address only to a member who may view orders.
The confirmation
Section titled “The confirmation”ebitex-order-confirmation-template finds its order in the device’s pending-order entry, not in the address (the
return address is sent before the order exists). It reads the order with the cart token, shows “waiting” and
polls on a capped back-off, then shows the order number, the lines, the totals, any shipments and the state of
each digital line’s download, with no click from the shopper. With no pending order it shows the section’s
not-found text; after a few minutes of waiting it says so and offers to check again. A cart token reads its order
for 30 days.
What is kept on the device
Section titled “What is kept on the device”Two JSON entries, both written by the package and nothing else:
| Entry | Holds | Dropped |
|---|---|---|
ebitex.cart.<store key>.<currency> |
id, token, at |
When the server says the cart is gone, or after 30 days untouched |
ebitex.order.<store key> |
id, token, at (the pending order) |
After the confirmation has seen it paid and a day more, and after 30 days whatever happened |
The cart token is strictly necessary state: it makes the cart and the order work, and it is used for nothing else, so it needs no consent. List it in your cookie notice as strictly necessary. Nothing the shopper types is kept.
Storage adapters
Section titled “Storage adapters”import { cookieAdapter, localStorageAdapter, memoryAdapter } from '@ebitex/commerce-kit-react'
<CommerceProvider commerce={commerce} cart={{ storage: cookieAdapter() }} />localStorageAdapter()is the default. Every access is guarded, so a private window or blocked storage degrades to memory: the cart works for the life of the page and nothing throws.cookieAdapter()is opt-in, for a host that renders on a server and wants to read the cart. It writes a first-party cookie withSameSite=Lax,Secureon https andPath=/. Do not widen its path or domain: the cart token is a secret.memoryAdapter()keeps nothing across reloads.
A second tab on the same site follows the first: a change in one is read by the other within a second.
Recognition is separate
Section titled “Recognition is separate”The package works the same whether or not the shopper has agreed to be recognised, and never stores a visitor
token. If you give the provider a visitors instance (the visitors SDK, or any
object with token, consent and subscribe), it sends the visitor token beside the cart token only while
consent is granted and the token is a recognition token, so the cart and the order are joined to the visitor the
shopper agreed to be. A session token, or no consent, sends none. When the instance forgets the device (both
token and consent become null), the package removes its two entries, and Commerce clears the cart token from
that visitor’s orders so a forgotten device cannot read one back. Withdrawing consent alone does not clear the
cart. If you do not use that instance, useCart().clear() does it.
What must not be done
Section titled “What must not be done”- Do not use the cart token or the cart id as an analytics, advertising or A/B identity, or to count visits or page views.
- Do not derive audience membership, personalisation or recommendations from a cart’s contents for a visitor who has not granted recognition.
- Do not join a cart or an order to a person except through a recognition token or a proved sign-in.
- Do not send the cart token to Audience, Content, Forms, Assets or any third party; do not put it in a URL, a
ctxbag, an interaction or an event. - Do not persist a visitor session token to make any of this easier. The visitors SDK’s rule stands.
- Do not keep the token beyond its cart and its order, and do not share one token between stores.
- List this storage in your cookie notice as strictly necessary, and make sure your own privacy notice covers collecting a delivery address and a phone number at your checkout.
Take the cart over
Section titled “Take the cart over”createCartStore (no React) and useCart() give you the snapshot (cart, count, pending, fault) and the
actions add, setQuantity, remove, setAddress, pay and clear, so a host can draw its own cart.
Product images
Section titled “Product images”A product’s pictures are Assets items. The renderer resolves each one through your Content client against the
environment’s Assets connection, once per picture for the life of the page. If your Assets connection is not
called ebitex-assets, tell the provider with assetsProvider. An asset outside the connection’s channel, or a
restricted one, is drawn as an empty box, never a broken image.
Labels and languages
Section titled “Labels and languages”The shop’s interface words (In stock, Load more, Add to cart, Pay, and so on, fifty-four in all) are
fields of the Store labels value on the Storefront Component, so they are translated in Content and
changed without a deploy. An empty label falls back to English, and a labels prop on the provider wins over
both. Prices are formatted from minor units with Intl.NumberFormat in the Content client’s locale, and the
country list comes from Intl.DisplayNames.
Product names, attribute values and option values come from Commerce in one language. Translate headings and texts in Content instead.
Accessibility
Section titled “Accessibility”Options are a radio group per axis, moved with the arrow keys. A value that is not offered stays focusable and says so in words. A changed price, availability or cart total is announced politely. The gallery is a list of buttons that never moves by itself, the list’s search field has a visible label, and Load more moves focus to the first new card. The drawer is a labelled modal dialog; removing a line moves focus to the next line or to the empty message. Controls are at least 24 by 24 CSS pixels, and everything draws at 320 pixels wide.
Take it over, a piece at a time
Section titled “Take it over, a piece at a time”Replace one Template’s entry in the renderer map, { ...commerceRenderers(), 'ebitex-product-card-template': MyCard },
or build your own section from the package’s ProductScope and useProduct. Draw inside the starter kit’s Frame
to keep a section’s width, background and appearance.