Commerce storefronts in Luat
The storefront blocks of Storefront and checkout render on your site through the Luat package @maravilla/studio (see Luat sites). The package is helpers first, default renderers second: every block comes with a default renderer you can keep, restyle or replace with your own markup, while the money, consent and mandatory-step rules stay below the renderer.
The contract
- The block content as stored. Label fields (
heading,empty_text,submit_label…) are translatable and inline-editable in Studio; empty means “the default”. Settings (source,columns,kinds…) are plain fields. storefront_blocks.hydrate(c, content, opts), called once by the page loader. It walks the page content, attaches_datato everystorefront:*block and returns{ cache = "public" | "private", status, head }. A GET runs SQL reads only: no function call, no guest created.storefront_blocks.action(c, ctx, form, content, opts)handles a POST of any storefront form and returns{ redirect, flash, status = 303 }. Forms post to the page’s own URL.- Helpers for custom renderers: money formatting with the currency’s exponent,
storefront_view(label text with its default, edit annotations, htmx swap attributes), andstorefront_rules.
-- page loader of a story page that carries storefront blocks
local blocks = require("@maravilla/studio/storefront_blocks")
local c = studio:commerce(ctx, { store_path = "/stores/webshop" })
local out = blocks.hydrate(c, page.content, {
lang = lang, editing = editing, mock = editing,
urls = { shop = "/en/shop", basket = "/en/basket", order = "/en/order", here = here },
route = { product = slug },
})
-- the page's POST
local r = blocks.action(c, ctx, ctx.form, page.content, same_opts) -- { redirect, flash, status = 303 }
Put out.cache into Cache-Control: a page with a basket or a buyer’s documents is private. In the editor (mock = true) the blocks render sample data from the store.
What a renderer cannot change
hydrate and action compute prices, totals, the tax note, stock, the payment methods (the site’s allowed providers intersected with the store’s enabled methods), the consents, the mandatory checkout steps (a step the engine needs that an author removed is appended), quantity ceilings and the account mode. A custom renderer cannot widen any of them, and the engine checks them again on the order.
Replace a renderer
Register your own component for a block type; keep the form protocol (op=add_goods, op=add_ticket, op=checkout with request_id for idempotency …):
-- src/lib/blocks.lua (the site's block registry)
return { ["storefront:Checkout"] = function() return require("$lib/components/MyCheckout") end }
<script>
local V = require("@maravilla/studio/storefront_view").new(props, "Checkout")
local d = V.d -- _data: d.b (basket), d.steps, d.methods, d.consents, d.request_id …
</script>
{#if d.b}
<form method="post" action={d.action} {...V.block}>
<input type="hidden" name="op" value="checkout"><input type="hidden" name="request_id" value={d.request_id}>
<h2 {...V.field("heading")}>{V.text("heading")}</h2>
<input name="name" required><input name="email" type="email" required>
{#each d.methods as m}<label><input type="radio" name="payment_provider" value={m.id}> {m.title}</label>{/each}
<button>{V.money(d.b.total, d.b.currency)}</button>
</form>
{/if}
Wording
Each visitor-facing string resolves in this order: the block’s own translatable field, the block’s messages rows (refusal code to text, authored in Studio), the dictionary your template passes as opts.labels (any language), the package’s built-in set (en, de, fr, it, ja). Refusals arrive as codes (sold_out, over_max, date_required …); the words are yours.
Recurring events and dates
c:occurrences(event_path, { days = 90 }) returns the dates of a series with their sale state, places left and price from; c:pools(event_path, { occurrence_date = … }) the categories of one date. The Ticket selector block does this for you and renders a date list or a month calendar; a date is part of the claim, so a sold-out or cancelled date is refused by the engine.
Product SEO
hydrate returns head for a page whose Product detail resolved a product: title, description, image, canonical, noindex, and schema.org Product JSON-LD with price, currency and availability from the engine. Put it into your layout’s <head>.
B2B blocks
storefront:Enquiry, MyQuotes, MyOrders and MyInvoices follow the same contract. Reads run as the signed-in buyer (row-level security); writes are request nodes in the buyer’s home. Ops: enquiry, quote_accept, quote_decline, reorder, invoice_pay. Signed-in buyers see their customer prices in the product blocks.
Progressive enhancement
studio.storefront_client.script_tag() adds small web components (variant picker, hold timer, delivery total, basket badge). Without JavaScript every date is a link and every form a normal POST.
Start from a template
The starter templates contain working pages for each of these: copy the page loader and the story pages, then change the wording in Studio.
Pilot documentation. Studio is in a partner pilot. Screens and YAML shown here are current as of the version noted on each page; tell your Maravilla contact when something does not match what you see.