Skip to content

Commerce Foundations is our pre-built Craft Commerce store. See what it includes

Data and backfill

How sales data gets into the plugin, and how to rebuild it. Audience: store admins and developers maintaining a store.

The two tables reports read from

The plugin keeps its own copies of order data rather than querying Commerce live on every page.

Variant sales holds one row per variant per completed order: quantity, line totals, the discount attributed to the line, and the product and variant titles and SKU as they were at the time of sale. The Products and Locations reports, the dashboard’s product widgets, and the Twig variables read this table.

Daily stats holds one row per calendar day: that day’s orders, revenue, discounts, shipping, tax, items sold, customer counts, AOV, and average items per order. The dashboard’s KPI cards, sparklines, and overview chart read this table.

The Orders, Transactions, and Customers reports read Commerce’s own tables and need neither. See the schema reference for the columns.

How data stays current

Both tables update whenever a completed order is saved: the initial completion, and every later save such as an admin editing line items, adding a manual discount, or changing the status. The order’s rows are deleted and re-inserted, and its day is re-aggregated.

This runs on the request that saved the order, not through the queue.

Historical rows keep the product title and SKU frozen at the time of sale, so renaming a product does not rewrite history, and a product deleted after it sold keeps its sales.

Backfilling

A fresh install has neither table populated, so every past period reports zero. Backfilling reads your existing completed orders and fills them in. Run it after installing, and after clearing either table.

Already-recorded orders are skipped, so running a backfill twice is safe. Daily stats rebuild from Commerce’s orders rather than from the variant sales table, so the two are independent; running the order backfill first fills the product reports and the dashboard together.

The refresh- variants clear the table before rebuilding, leaving the reports empty until the queue finishes. See console commands for every command, its options, and which ones queue.

The same operations are at Utilities -> Best Sellers, which needs the best-sellers:backfill permission and adds an optional date range on the order backfill.

When a backfill hits a problem

An order that cannot be processed is written to the backfill log instead of failing the job. Entries are listed on the Operations page with the order reference and the message.

Fix the underlying problem, then re-run the backfill.

Uninstalling

Uninstalling drops all three of the plugin’s tables. Commerce’s own order data is untouched, so reinstalling and backfilling reproduces the reports.

Think we might be a fit?

Start a conversation
See if we’re a fit