Shop settings and business customers
This page covers what a storefront reads about the shop itself: its features, currencies, locales, regional format and the platform's own settings. It also covers customer and salesOrders, the calls for business customers who order on account.
customer and salesOrders are for business (B2B) customers only. Each call needs the person's shop token, which they get by signing in through the shop's login; see Business login. A guest storefront never calls them.
Every method takes an optional last argument, context: { headers?, signal?, orgId? }. It is left out of the tables below unless a method needs it.
Shop features and settings
The features methods read the public organisation document, GET /organization/v1/{orgId}. Each call reads it again, so read once per page or build and pass the answer down. Every method except getStoreAmounts takes the same optional first argument:
| Name | Type | Required | What it does |
|---|---|---|---|
options.orgId | string | no | Another organisation than the client's own. |
features.list
Lists the organisation's features and whether each is on.
eldra.features.list(options?: { orgId?: string }, context?): Promise<{ feature: string; enabled: boolean }[]>Returns an array of { feature, enabled }, such as { feature: 'ECOMMERCE', enabled: true }. It is [] when the organisation publishes none.
const features = await eldra.features.list();
const hasForms = features.some((row) => row.feature === 'FORMS' && row.enabled);features.isEnabled
Answers whether one feature is on. Use it to hide the shop or the content pages of an organisation that has them switched off.
eldra.features.isEnabled(feature: 'CMS' | 'ECOMMERCE', options?: { orgId?: string }, context?): Promise<boolean>| Name | Type | Required | What it does |
|---|---|---|---|
feature | 'CMS' | 'ECOMMERCE' | yes | The feature to check. |
Returns true when the feature is on, false when it is off or missing.
if (await eldra.features.isEnabled('ECOMMERCE')) showCartButton();Only CMS and ECOMMERCE
isEnabled and getCapabilities know these two features. To check any other feature, such as FORMS, read features.list().
features.getCapabilities
Answers what the storefront can show, in one object.
eldra.features.getCapabilities(options?: { orgId?: string }, context?): Promise<EldraFeatureCapabilities>Returns
| Field | What it is |
|---|---|
cms | CMS is on: content pages can be read. |
ecommerce | ECOMMERCE is on. |
catalog | The same as ecommerce. |
products | The same as ecommerce. |
features | { CMS?: boolean, ECOMMERCE?: boolean }, as the organisation set them. |
const { cms, ecommerce } = await eldra.features.getCapabilities();
const nav = [
cms && { href: '/blogg', label: 'Blogg' },
ecommerce && { href: '/peysur', label: 'Peysur' },
];features.getCommerce
Answers what the shop sells in: its currency, the currencies it offers and how tax is shown.
eldra.features.getCommerce(options?: { orgId?: string }, context?): Promise<EldraOrganizationCommerce | null>Returns the commerce settings, or null when the shop has not set them up.
| Field | What it is |
|---|---|
currency | The shop's own currency, such as ISK. Every product has a price in it. |
currencies | The currencies the storefront may offer. |
defaultCurrency | The currency pages are built in and a visitor starts in. |
taxInclusivePricing | true when prices already include VAT. Show them as they are. |
defaultTaxRate | A fraction, such as 0.24. Applies to shipping and to products without their own rate. |
const commerce = await eldra.features.getCommerce();
const currency = commerce?.defaultCurrency ?? commerce?.currency ?? null;
// Offer commerce?.currencies in a currency picker; switch a cart with cart.setCurrency.Do not guess a currency
When the answer is null, show prices as plain numbers. Never put a currency sign on them that the shop did not choose.
features.getLocales
Answers the shop's content locales: which one is the default and which others exist. Use it to decide which language lives at which URL.
eldra.features.getLocales(options?: { orgId?: string }, context?): Promise<{ default: string; supported: string[] } | null>Returns { default, supported }, or null when the organisation has configured none.
| Field | What it is |
|---|---|
default | The locale served at the site root, such as is-IS. |
supported | Every configured locale, the default first, without duplicates. |
The answer is checked before it reaches you. A broken record reads as null, the same as none.
const locales = await eldra.features.getLocales();
// { default: 'is-IS', supported: ['is-IS', 'en-US'] }
// Icelandic at the site root, English under its own path prefixfeatures.getRegion
Answers how the shop writes money, numbers and dates, and which time zone it uses. This is separate from the content language: an English page of an Icelandic shop still writes 24.900 kr..
eldra.features.getRegion(options?: { orgId?: string }, context?): Promise<EldraOrganizationRegion | null>Returns the regional format, or null when none is published.
| Field | What it is |
|---|---|
countryCode | ISO 3166-1 alpha-2 in upper case, such as IS. '' until the merchant sets one. |
formatLocale | The BCP 47 tag to format with, such as is-IS. |
timeZone | The IANA time zone for dates and times, such as Atlantic/Reykjavik. |
A tag or time zone your runtime cannot use makes the whole answer null. Fall back to your own locale then.
import { formatPrice } from '@eldrajs/sdk/format';
const region = await eldra.features.getRegion();
formatPrice(24900, 'ISK', region?.formatLocale ?? 'is-IS'); // "24.900 kr."features.getStoreAmounts
Answers the shop's amounts for price tokens in its texts, such as "free shipping over …". Read it once at build time.
eldra.features.getStoreAmounts(context?): Promise<StoreAmounts>This method takes no options; pass context only.
Returns amounts in minor units, by currency. Today it has one entry, freeShippingThreshold: the lowest free-shipping threshold among the active delivery methods in each currency.
{ "freeShippingThreshold": { "ISK": 15000, "EUR": 10000 } }It is {} when no delivery method has a threshold. A currency with no threshold is left out.
const amounts = await eldra.features.getStoreAmounts();
const freeOver = amounts.freeShippingThreshold?.ISK; // 15000 = 15.000 kr.These amounts are minor units
Unlike cart amounts, these are in the currency's smallest unit. 10000 EUR is €100.00. ISK has no smaller unit, so 15000 ISK is 15.000 kr.
Platform settings
platform.config
Reads the platform's own public settings. Today that is where the hosted checkout lives.
eldra.platform.config(readOptions?: { signal?: AbortSignal }): Promise<{ checkoutUrl: string | null }>| Name | Type | Required | What it does |
|---|---|---|---|
readOptions.signal | AbortSignal | no | Stops your own wait. The shared read carries on for others. |
Returns { checkoutUrl }, or { checkoutUrl: null } when the platform publishes none.
The read is made once per client and shared by every caller. A failed read is not kept, so the next call tries again. It sends no organisation header, and it takes no context.
const { checkoutUrl } = await eldra.platform.config();Use checkout.url() for the link
To send a shopper to checkout, call checkout.url(). It reads this setting and builds the full address for a cart.
Business customers
Call these from your server only. Pass the person's token, and their active company when they buy for several, in context.headers. bearer(token) and customerHeaders(token, customerId) build the headers. Never send the token from the browser.
Every answer, errors included, is sent with Cache-Control: private, no-store. Never cache one, and render these pages per request.
These errorIds can come from every call below:
| errorId | Status | What to do |
|---|---|---|
SHOP_TOKEN_INVALID | 401 | The token is missing, expired or from another shop. Refresh it or sign in again. |
SHOP_NO_MEMBERSHIP | 403 | The login buys for no company. |
SHOP_CUSTOMER_NOT_MEMBER | 403 | X-Customer-Id is not one of the person's companies. |
FEATURE_DISABLED | 403 | Business sales are off. Continue as a guest. |
SHOP_CUSTOMER_REQUIRED | 409 | The person buys for several companies. Send X-Customer-Id. |
SHOP_LOGIN_UNAVAILABLE | 503 | The login service is unreachable. Try again. |
customer.me takes no company. It can answer SHOP_TOKEN_INVALID, SHOP_NO_MEMBERSHIP, FEATURE_DISABLED and SHOP_LOGIN_UNAVAILABLE.
customer.me
Reads the signed-in person and the companies they buy for. Call it after sign-in to show their name and a company picker.
eldra.customer.me(context: { headers: { Authorization: string } }): Promise<EldraCustomerMe>| Name | Type | Required | What it does |
|---|---|---|---|
context.headers | HeadersInit | yes | The token, as bearer(accessToken). |
Returns
| Field | What it is |
|---|---|
shopUser | The person: id, email, firstName, lastName. |
memberships | Each company they buy for: customerId, customerName, role (BUYER or ADMIN), status (INVITED or ACTIVE). |
import { bearer } from '@eldrajs/sdk';
const me = await eldra.customer.me({ headers: bearer(session.accessToken) });
const companies = me.memberships.filter((m) => m.status === 'ACTIVE');
// "Halló, " + me.shopUser.firstName; one company: use companies[0].customerIdBuild the client with the organisation's UUID as orgId. The gateway refuses an alias with SHOP_TOKEN_INVALID.
customer.locations
Lists the active company's delivery locations, the default first. Use it for the "Deliver to" choice before a sales order.
eldra.customer.locations(context: { headers }): Promise<{ data: EldraCustomerLocation[] }>| Name | Type | Required | What it does |
|---|---|---|---|
context.headers | HeadersInit | yes | customerHeaders(accessToken, customerId). |
Returns { data }. data is [] for a company with none. Each location has id, name, addressLine1, addressLine2, postalCode, city, countryCode, phone and isDefault.
import { customerHeaders } from '@eldrajs/sdk';
const headers = customerHeaders(session.accessToken, session.customerId);
const { data: locations } = await eldra.customer.locations({ headers });
const deliverTo = locations.find((l) => l.isDefault) ?? locations[0];Sales orders
A sales order is placed on account: the shop sends the goods and invoices the company later, so there is no payment step. The calls act for the person's active company. The full flow, every errorId and the reorder pattern are in Sales orders.
Every call needs customerHeaders(accessToken, customerId) in context.headers. Only 401 SHOP_TOKEN_INVALID means the person must sign in again. 502 SALES_ORDER_UPSTREAM_REFUSED means the shop's order service refused the platform: try again later, and never sign the person out over it.
salesOrders.preview
Prices the company's cart exactly as placing it would, and writes nothing. Show it before the person places the order, because the order uses the company's current prices.
eldra.salesOrders.preview(input: { cartId: string; locationId?: string }, context: { headers }): Promise<EldraSalesOrderPreview>| Name | Type | Required | What it does |
|---|---|---|---|
input.cartId | string | yes | The cart, bound to the active company. |
input.locationId | string | no | One of the company's delivery locations. Left out, the default is used. |
Returns
| Field | What it is |
|---|---|
lines | title, sku, quantity, unitPrice, finalPrice, availableNow. |
subtotalAmount, taxAmount, totalAmount | The order's totals. |
currency | ISO 4217 code. |
paymentTermLabel, paymentTermDays | The payment terms. Show the label when there is one, else the days. |
delivery | Where the order goes. |
credit | { status, wouldBlock, creditCurrency? }. No limit or balance is ever answered. |
availableNow is information only. An order on account is never refused for stock.
Errors worth handling
SALES_ORDER_CART_NOT_BOUND(409): the cart is not this company's. Add to it signed in first.SALES_ORDER_CART_EMPTY,SALES_ORDER_TOO_MANY_LINES(400): fix the cart.SALES_ORDER_LINE_INVALID(400):errors.variantIdcannot be ordered. Remove it.ORDER_PRODUCT_UNAVAILABLE(409):errors.variantIdsare no longer sold.SALES_ORDER_LOCATION_UNKNOWN(409): reload the company's locations.CUSTOMER_BLOCKED(409): the company may not order now. Ask the person to contact the shop.CART_NOT_FOUND(404): the cart is gone.
const preview = await eldra.salesOrders.preview({ cartId, locationId: deliverTo.id }, { headers });
if (preview.credit.wouldBlock) {
showMessage('This order is over your credit limit. Contact the shop.');
}Check credit.wouldBlock first
When it is true, placing the order will be refused for credit. Say so before the person presses Place order.
salesOrders.create
Places the company's cart as a sales order. The cart is removed once the order is placed.
eldra.salesOrders.create(
input: { cartId: string; locationId?: string; purchaseOrderNumber?: string; customerOrderDate?: string; note?: string },
options: { idempotencyKey: string },
context: { headers }
): Promise<EldraSalesOrder>| Name | Type | Required | What it does |
|---|---|---|---|
input.cartId | string | yes | The cart, bound to the active company. |
input.locationId | string | no | A delivery location. Left out, the company's default. |
input.purchaseOrderNumber | string | no | The buyer's own reference, at most 40 characters. |
input.customerOrderDate | string | no | The date on the buyer's own order, YYYY-MM-DD. |
input.note | string | no | A note to the shop, at most 1000 characters. The company's other members see it too. |
options.idempotencyKey | string | yes | 1 to 255 printable ASCII characters, no spaces. A UUID works. |
Returns the order: id, orderNumber, salesStatus, lines, subtotalAmount, taxAmount, totalAmount, currency, delivery, placedAt and warnings. A warning, such as SALES_ORDER_STOCK_NOT_SET_ASIDE, names a step the shop finishes later. The order stands.
Errors worth handling: everything preview answers, and also:
SALES_ORDER_CART_ALREADY_ORDERED(409): the cart is already the ordererrors.salesOrderId. Show that order.SALES_ORDER_CREDIT_LIMIT_EXCEEDED(409): over the credit limit. No figures are answered.SALES_ORDER_CREDIT_CURRENCY_MISMATCH(409): the company's credit is kept in another currency. Do not retry.ORDER_IDEMPOTENCY_CONFLICT(409): the key was used for another body. Mint a new one.
Without a usable key the call rejects with EldraIdempotencyKeyError and sends nothing. That is a bug in your code, never a reason to retry.
const order = await eldra.salesOrders.create(
{ cartId, locationId: deliverTo.id, purchaseOrderNumber: 'PO-2026-118' },
{ idempotencyKey: attempt.idempotencyKey },
{ headers }
);
cartSession.forget();
navigateTo(`/account/orders/${order.id}`);Retry with the same key
A 502, a 503 or a timeout may come after the order was placed. Retry with the same idempotency key, which replays that order instead of placing a second one. Mint a new key only when the cart or the form changes.
salesOrders.list
Lists the company's sales orders, newest first. Use it for the order history page.
eldra.salesOrders.list(options?: { page?: number; pageSize?: number; status?: string }, context: { headers }): Promise<EldraSalesOrderList>| Name | Type | Required | What it does |
|---|---|---|---|
options.page | number | no | The page to read. |
options.pageSize | number | no | 1 to 50. Default 50. |
options.status | string | no | One of OPEN, ON_HOLD, PART_DELIVERED, DELIVERED, CANCELLED. |
Returns { data, meta }. data is [] when there are none. Each order has id, orderNumber, placedAt, purchaseOrderNumber, salesStatus, totalAmount, currency, lineCount and backorderQuantity. meta has page, pageSize, total, totalPages, hasNext and hasPrev.
const { data: orders, meta } = await eldra.salesOrders.list(
{ page: 1, pageSize: 20, status: 'OPEN' },
{ headers }
);salesOrders.get
Reads one sales order with its lines. Use it for the order detail page.
eldra.salesOrders.get(salesOrderId: string, context: { headers }): Promise<EldraSalesOrder>| Name | Type | Required | What it does |
|---|---|---|---|
salesOrderId | string | yes | The sales order. |
Returns the order, with the fields listed under create. Each line has title, sku, quantity, quantityDelivered, backorder, inStockNow, unitPrice and finalPrice. warnings is always [] on a read.
Errors worth handling: SALES_ORDER_NOT_FOUND (404). Another company's order answers the same as one that does not exist.
const order = await eldra.salesOrders.get(params.id, { headers });
const waiting = order.lines.filter((line) => line.backorder > 0);See also
- SDK reference: creating the client, origins and errors.
- Business login: signing in and keeping the token.
- Customer prices: a business customer's catalog prices and cart.
- Sales orders: the full ordering flow and error table.