Part of the Commerce ecosystem · 506 projects
Commerce Live Data shows each customer the price and per-location stock that your ERP holds for them, while product pages stay cacheable. Carts are priced live, every call has a hard timeout, and a circuit breaker keeps a failing ERP from taking the store down.
Status: Stable. 1.0.0 is the first release.
Why
In many B2B stores the price a customer pays and the stock in each warehouse are held in the ERP, and differ by customer. Importing them on a schedule goes stale. Rendering them into the page breaks caching. A slow ERP also holds PHP workers while every page waits for it. This module puts the same placeholder in the page for everyone, loads each customer's figures after it, bounds every call, and stops calling a provider that keeps failing.
Features
Prices
- A price resolver, run ahead of Commerce's default one, asks a price provider for the customer, store and quantity. Prices shown on pages may come from a cache; carts and orders always ask the provider and are never priced from a cached display price.
- The provider is told who is asking by a customer key: the user ID, or a field on the account such as an account number or price group. Users who share a key share cached prices. Anonymous visitors are priced with a key you set, or see the catalog price or a link to log in.
- Before payment, each checkout step prices again any line whose live price is older than a set age (300 seconds by default), and stops the customer if one changed. At placement, older prices are checked with the provider again: the order keeps the price the customer saw, and a change or a failed check is recorded on the line and logged.
- Each order item records where its price came from (the provider, an earlier live price, the catalog price, or another resolver) and when. Orders placed with lines not priced live are logged, and a "Live prices" line on the order page counts them by reason. A provider can instead refuse checkout while a line is on the catalog price.
- A zero price counts as "no price" unless the provider allows zero prices, a price in another currency than the one asked for is refused, and prices are rounded to the currency unless that is switched off. A cart never mixes currencies.
Availability and locations
- A "Live availability" field on product variations, with the "Live availability by location" formatter: quantities or words ("In stock", "Low stock", "Out of stock") per location, with an optional total and a low-stock threshold.
- Exact quantities only for users with the "View live stock quantities" permission. Everyone else sees words, whatever the display asks for.
- Locations are this module's own (a name and the provider's code for it), or Commerce Stock's when its Local Storage module is installed, with a field you choose holding the provider's code. Codes not on the list are neither shown nor counted. If none of an item's codes match, its availability is "unknown", never "out of stock".
- Optional enforcement: refuse quantities above what is available when an item is added and when the cart is recalculated. The provider is asked fresh each time, and only a definite "not enough" blocks: a failure, a stale answer or a backorderable item never does.
Pages that stay cacheable
- The "Live price (loaded per customer)" formatter and the availability formatter put a placeholder in the page that is the same for every visitor, so the page cache and the dynamic page cache keep working. The price can show the catalog price struck through beside it when they differ.
- Values load after the page in batched requests through core's HTMX, or, for signed-in visitors if you choose, in the page itself (streamed by BigPipe when it is installed).
- The fragment endpoint takes the customer only from the session and checks view access to each variation. Cached fragments vary by a keyed hash of the customer key, never the key itself. Requests are rate limited per user, or per IP address for anonymous visitors (600 a minute by default).
- The same data as JSON at
/commerce-live-data/data, for headless and decoupled front ends, under the same access and caching rules. - Commerce's own "Calculated" price formatter keeps working safely: the module adds the customer cache context and the lookup's lifetime to it, and keeps such anonymous pages out of the internal page cache. The status report recommends the Live price formatter instead.
When the ERP is slow or down
- The HTTP provider sets a connect timeout and a total timeout on every call (1 and 2.5 seconds by default, at most 10), follows no redirects, and caps the response size while reading.
- A circuit breaker for each provider: after a number of failures in a row (5 by default) it skips the provider for a cooldown (30 seconds by default), then one worker sends a probe. A large cart is looked up in batches within a time budget (5 seconds by default); batches left when it runs out are skipped and fall back.
- Separate display cache lifetimes per provider for found and not-found answers. Stale prices can be shown while they are refreshed after the response (up to 60 seconds past their lifetime by default) or while the provider fails (600 seconds, with a notice). Both stale windows are off by default for availability.
- When the provider cannot answer, customers see their last known price within that window, or the catalog price, with a notice. Carts fall back to the catalog price, or by policy to the line's last live price if it is recent enough. Every fallback in a cart or order is logged; display fallbacks are logged at most once a minute per provider by default.
- Before connecting, the endpoint is checked: https only unless http is allowed, no credentials in the URL, and every address the host resolves to must be public unless private network addresses are allowed. The checked addresses are then pinned for the connection.
Providers
- Two plugin types, price providers and availability providers. Each has an "HTTP JSON endpoint" provider, which posts each batch of items to your endpoint, and a "Fake" provider that answers from a table typed into its settings and can simulate an error, a timeout or a malformed answer, for building displays and rehearsing outages before the ERP is connected.
- Credentials stay in the Key module and are sent as a bearer token, a custom header, HTTP Basic or a query parameter added at request time.
- The HTTP provider checks answers strictly: every requested item must be answered, a found item needs an amount (or, for availability, a list of locations), and a negative amount or any other shape fails the whole call, so a change on the ERP side is noticed rather than read as "no price".
- Several providers per kind, each covering the product variation types you choose; the one with the lowest weight is used.
- An ERP whose JSON has another shape can be mapped in two event subscribers, and the mapped answer is still checked. Anything else (SOAP, a vendor SDK) needs a provider plugin.
Monitoring and other code
- A status page per provider: circuit state, cache hit rate, calls, failures, fallbacks and latency over the last 24 hours, recent failures, and links to test a lookup or reset a circuit.
- Status report entries for misconfigured providers, open circuits, unmatched location codes, a customer key field that customers can edit, displays using the Calculated formatter, and a server that cannot refresh after the response.
- Drush commands to show status, check for problems (exit 1, for monitoring), run a lookup, reset a circuit and invalidate cached data for a SKU or for everything.
- For other code: events to choose the customer key and the price currency, adjust answers, filter and order locations per customer, react to fallbacks and adapt the HTTP providers; a cache tag per SKU to invalidate from an ERP webhook; and services to look up prices and availability.
Requirements
- Drupal 11.3 or later, or Drupal 12. Drupal 12 needs a Drupal Commerce release that supports it; Commerce 3.3 supports Drupal 10.3 and 11.
- PHP 8.3 or later with the curl extension.
- Drupal Commerce 3.3 or later, or Commerce 4, with its Order, Price, Product and Store modules.
- Key 1.19 or later.
- An ERP or other service that answers price and stock requests as JSON over HTTP in the format the README describes, or a provider plugin of your own.
- Optional: Commerce Stock 3 with its Local Storage module, whose locations are then reused; core's BigPipe, to stream the in-page loading strategy; Drush, for the commands.
- Any database Drupal supports (MySQL or MariaDB, PostgreSQL, SQLite).
Installation
Install with Composer, then enable the module:
composer require drupal/commerce_live_data drush en commerce_live_data
This also enables Remote Data Cache (remote_data_cache), a submodule that holds the timeouts, the cache, the circuit breaker and the health records. It has no Commerce dependency, but for now treat it as part of this module. Nothing is called until you add a provider; until then catalog prices are used.
Configuration and permissions
Everything is at Administration » Commerce » Configuration » Live prices and availability (/admin/commerce/config/live-data), with tabs for Status, Price providers, Availability providers, Locations and Settings. Store the provider's credentials in a key first. Then add a price provider and an availability provider, define locations with the codes the provider uses (or choose Commerce Stock's), and review where the customer key comes from and what anonymous visitors see. Last, in each product variation type's Manage display, set the Price field to the "Live price (loaded per customer)" formatter and place the Live availability field with the "Live availability by location" formatter.
- Administer live prices and availability (restricted): configure providers, their endpoints and credential keys, locations and settings; reset circuit breakers; run test lookups against providers.
- View live data status (not restricted): see the status page, with provider health, circuit breaker states, hit rates and latency. It shows no customer data.
- View live stock quantities (not restricted): see exact quantities per location in live availability, on pages and from the JSON endpoint. Without it, availability is shown in words.
The fragment and JSON endpoints are open to anyone with Commerce's permission to view products, and check view access to each variation.
Using it safely
A customer key read from a user field must not be editable by the customer, or anyone could type in another account's number and see its prices; the status report warns when the field is on the account form. Untick "Prices differ between customers" only when that is true, because one cached answer then serves everyone. Leave "Allow private network addresses" and "Allow plain http" off for providers on the public internet.
What it does not cover
Live figures are not fed into Commerce Stock's stock service, so Commerce Stock's own checkers and stock level field still see Drupal's local stock. Refreshing a stale answer after the response needs PHP-FPM or LiteSpeed; on other servers an expired answer is fetched while the visitor waits, and the status report says so. The circuit breaker counts failures in a row, so a provider that fails every other call never opens it; those failures still show on the status page. The endpoints use the site's cookie authentication; a headless front end on another authentication provider adds it with a route subscriber.
Similar projects
Checked on drupal.org in November 2026.
- Commerce Pricelist keeps price lists inside Drupal. Choose it when you can import the ERP's prices on a schedule; this module is for stores whose prices must come from the ERP when they are charged, and close to it when they are shown.
- Commerce Stock tracks stock by location inside Drupal; its storefront formatter shows a single total. This module reuses its locations when its Local Storage module is installed.
- Commerce HTMX Cart uses HTMX for the cart only.
Support and maintenance
Report bugs and ask for features in the issue queue. Each release has notes describing what changed.
This project is not covered by Drupal's security advisory policy. Until it is, security issues are handled in the public issue queue and fixed in ordinary releases.
A read-only mirror is on GitHub at DanePete/drupal-commerce-live-data; development and issues stay on drupal.org.
Maintainer
Created and maintained by deadnorth (Dead North).
Ask your assistant about Commerce Live Data
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
- Commerce Core commerce_order
- Commerce Core commerce_price
- Commerce Core commerce_product
- Commerce Core commerce_store
- Key
- Commerce Live Data remote_data_cache
Required by
1 tracked project depends on this one
More in the Commerce ecosystem
Most installed first