@ebitex/commerce-kit-react
v1.1.349
Published
A React renderer for the ebitex storefront kit: a shop's products drawn from Commerce, as sections of a Content site, with the starter kit's tokens.
Maintainers
Readme
@ebitex/commerce-kit-react
A React renderer for the ebitex storefront kit: the kit's product Templates drawn from your Commerce store, as sections of a Content site. It shows products (a list with search, sort, filters and "load more", and a detail address for every active product with a gallery, price, options and stock), and it sells: a buy button, a cart in the header and on a page of its own, a pay form that sends the shopper to your payment provider's page, and an order confirmation.
It builds on @ebitex/starter-kit-react: the same tokens (--ebitex-*), Frame, Action and Media, so a storefront section sits beside a
starter section and takes the same width, background and appearance.
This package is private for now: it is built and tested with the kit but not yet installable from npm.
Use it
import { createProductData } from '@ebitex/commerce-kit-react'
import { CommerceProvider, commerceRenderers } from '@ebitex/commerce-kit-react/react'
const productData = createProductData(commerce) // a route data definition for the tag "commerce.product"
<EbitexProvider client={content}>
<CommerceProvider commerce={commerce} content={content} productData={productData}>
<ContentProvider client={content} renderers={{ ...ebitexRenderers(), ...commerceRenderers() }}>
<Experience path={pathname} routeData={[productData]} />
</ContentProvider>
</CommerceProvider>
</EbitexProvider>@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";You need two browser-safe delivery keys restricted to your site's origins, one for Content and one for Commerce, and the Commerce key must read the store the Content site's Commerce registration points at.
The host keeps its one catch-all <Experience>: Content resolves /shop/products/trail-runner to the kit's parameterised node and hands over { key: 'trail-runner' }.
Selling
Give the provider cart and the cart is on; leave it off and the package draws no cart, reads no storage and makes no cart request.
<CommerceProvider commerce={commerce} content={content} productData={productData} cart={{}} visitors={visitors /* optional */}>- A cart token, not the shopper's identity. The first add creates a cart and Commerce answers a cart token, once: a secret for that one cart. The package keeps it in
localStorage(a cookie adapter,cookieAdapter(), is opt-in for a host that renders on a server;memoryAdapter()keeps nothing) and sends it asX-Cart-Tokento the Commerce cart and order routes, nowhere else. - Recognition is separate. The package never stores a visitor token. With a
visitorsinstance it sends one beside the cart token only while that instance holds a recognition token (consent granted). A session token, or no consent, sends none, and selling works all the same. When the instance forgets the device the package removes its own entries (or calluseCart().clear()). - Two entries on the device, both JSON:
ebitex.cart.<store key>.<currency>(id,token,at) andebitex.order.<store key>, the pending order written before the shopper leaves for the payment page, because the return address cannot carry the order id. A shopper who only browses writes nothing. Nothing the shopper types (email, name, address) is ever written to the device. List this storage in your cookie notice as strictly necessary. - The pay form collects what checkout needs (and, when something ships, the recipient, two address lines, a city and a phone), shows each refusal beside its field, takes one submit, and redirects to the provider. The confirmation reads the pending order from storage, asks Commerce on a capped back-off until the payment is confirmed, and then shows the order.
- The header cart.
commerceRenderers()also returnsebitex-site-header-template: the starter header with the cart button in itsendslot. Omit that one entry to leave it out, or place<CartButton />in your own header. - Without a
storeKey(andcurrency) incartthe provider asks Commerce for the store once per page: the only request made before a shopper adds anything. Give both to avoid it.
What must not be done with it:
- 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.
- Do not keep the token beyond its cart and its order, and do not share one token between stores.
For a host that draws the cart itself, createCartStore (no React) and useCart() give the snapshot (cart, count, pending, fault) and add, setQuantity, remove, setAddress, pay and clear.
What it draws
| Template | Draws |
|---|---|
| ebitex-product-hero-template | A gallery (single, thumbnails below or beside), the name, a lead and the presentations it holds. Also sets the page title, description and a schema.org Product block |
| ebitex-product-price-template | The price of the chosen variant, a struck-through compare-at price and a tax note. No price for an unpriced variant, never zero |
| ebitex-variant-picker-template | A radio group per option axis, or a listbox in the menu style. The choice is kept in the address (?size=41) |
| ebitex-product-inventory-template | In stock, backorder or out of stock, and with live on a count from one stock call for the chosen SKU |
| ebitex-product-detail-template | An editor's heading and rich text, and the attributes named by the product type's field names |
| ebitex-product-card-template | One product as a card that links to its address |
| ebitex-product-list-template | The store's products (or a hand-picked list), with search, sort and "load more". One Commerce request per page, and never a stock call |
| ebitex-buy-button-template | Adds the chosen variant to the cart. Disabled with "Choose an option" until every option has a value, and with "Sold out" for an out-of-stock variant; announces the addition politely. Draws nothing without cart |
| ebitex-cart-template | The cart's lines and quantities, the server's totals (no tax or total shown as zero before a country is given), the pay form and the terms |
| ebitex-order-confirmation-template | Waiting, paid (lines, totals, shipments, each digital line's entitlement), failed or not found |
| ebitex-order-history-template | A shopper signs in with their email (the content SDK's useSignIn; the Content client needs the audience option) and sees their orders, newest first, with each digital line's entitlement and the action the editor paired with its SKU |
| ebitex-product-stream-list-template | The authored product pages of the ebitex-products stream as cards (your title and summary, the product's picture and price in one productsByKeys call per page), with search over your words and category facets when its settings turn them on |
| ebitex-product-experience-template | An authored product page: the starter's experience with its product opened for the sections beneath it, so a product section left empty shows this page's product and no route is needed |
| ebitex-site-header-template | The starter's header with the cart button and its drawer (a modal dialog: focus trapped, Escape closes, focus returned) |
| ebitex-shop-experience-template | The starter's own experience renderer: a shop experience has the same shape |
Which product a section shows. Its own product field when it is set (a pinned product, which works on any experience); otherwise the authored product page it sits on; otherwise the product the address names. With neither, the section draws
nothing and, in development, says so. An address that names no product draws your site's not-found; a pinned product that is gone draws nothing for that one section and leaves the rest standing.
Price and availability always come from Commerce, in the browser. They are never taken from the product reference Content resolves, which can be minutes old and is always in the store's own currency. A fixed-size placeholder is shown until Commerce answers, so nothing moves.
The sitemap. The product address is a parameter, so the sitemap reports it under routes and leaves the values to you. await productSitemapEntries(commerce, { skip }) gives the content SDK's expand option one { key } per listed product, read a page at a time; skip takes the keys that have an authored page at their own address.
Labels and locales
The interface strings are the fields of the kit's ebitex-store-labels value on the ebitex-storefront Component, localizable in Content and edited without a deploy. An empty label falls back to
the English default; a labels prop on CommerceProvider wins over both. Money is formatted with Intl.NumberFormat from minor units and the currency's exponent, in the Content client's locale.
Stated limit: product names, attribute values and option values come from Commerce in one language. The editorial fields (heading, title, summary, body) are the way to a translated product for now.
A "yes", a "no", the list's error message and the pay form's field messages are English constants in this release, not yet labels. What a shopper is told when a payment cannot start, and the order confirmation's states, are labels (below).
When a payment cannot start, and the confirmation's states
A refused payment says what happened and what to do, in labels, and moves focus to the message: pay-stock-short (with line-short, or line-short-count and change-quantity, which fill {count}, on each line the refusal names), pay-provider-down, pay-tax, pay-subscription-alone, pay-offline (a request that got no answer), name-too-long (beside the Name field) and pay-error (anything else). A line marked short never disables Pay; the mark goes when the line changes and is never stored. The confirmation has a status line and a sentence for each state: order-failed and order-failed-text (the editor's Failed text replaces the sentence), order-not-found and order-not-found-text, order-unreachable, order-unreachable-text and order-unreachable-stopped (after three failed reads in a row), and order-slow-text beside Check again when the wait passes its cap. It never says the shopper was not charged.
Product images
A product's media are Assets item ids. Each is resolved through the Content client against your environment's Assets registration, once per id for the life of the page. Tell the provider the registration's
key with assetsProvider when your Assets registration is not named ebitex-assets; a section that holds a delivered ebitex-image reference (a hero's own media) teaches the provider the key as well.
An asset outside the channel the registration reads, or a restricted one, is "no image": a reserved box, not a broken picture.
Accessibility
Options are a radio group per axis named by the axis, moved with the arrow keys; a value that is not offered stays focusable and says "unavailable" in words and in its shape, never by colour alone. A price or availability that changes after a choice is announced politely. The gallery is a list of buttons carrying each picture's alternative text and never moves by itself. The list's search field has a visible label, and "load more" moves focus to the first new card. Targets are at least 24 by 24 CSS pixels.
Take it over, a piece at a time
Replace a Template's entry in the renderer map ({ ...commerceRenderers(), 'ebitex-product-card-template': MyCard }), or build your own section from ProductScope and useProduct, which give you the product,
the options chosen, the variant they name and select(axis, value). The pure half (@ebitex/commerce-kit-react, no React) has variant matching, formatMoney, the label defaults, createProductData and
productJsonLd, so a host that draws the storefront itself can reuse them.
