Skip to content

Configuration beta

Order Lifecycle is configured via the Craft control panel. Navigate to Settings → Order Lifecycle to adjust all settings.

Event Logging

These toggles control which event categories are recorded. All are enabled by default except "Log All Payment Transactions".

SettingDefaultDescription
Log Line Item ChangestrueCart line item additions, removals, and quantity updates
Log Order Status ChangestrueOrder status transitions
Log Order Complete EventtrueWhen an order is marked as complete
Log Order Paid EventtrueWhen an order is fully paid
Log Email Sent EventstrueOrder-related emails sent and failed
Log Coupon/Discount ChangestrueCoupon codes applied or removed
Log Address ChangestrueShipping and billing address set or removed
Log Customer ChangestrueCustomer email set or removed
Log Shipping Method ChangestrueShipping method selected or changed
Log Payment AttemptstrueEach payment attempt
Log Payment AuthorizedtruePayment authorization events
Log Payment CapturedtruePayment capture events
Log Payment RefundedtrueRefund events
Log All Payment TransactionsfalseEvery individual transaction state change (high volume - off by default)

Performance

SettingDefaultDescription
Async Queue LoggingfalseWrite log entries via the Craft queue instead of inline during the order save

When to enable async logging

By default every log entry is written synchronously inside Commerce's afterSave transaction. On a low-to-medium volume store this is imperceptible. On a high-volume store - flash sales, high concurrent checkout - this adds measurable latency to every order save.

Enabling Async Queue Logging moves the DB INSERT out of the request cycle entirely. The snapshot and change description are still computed synchronously (they are fast, in-memory operations), then a lightweight queue job handles the write.

Requirements before enabling:

  • Your Craft queue worker must be running continuously (php craft queue/listen or a supervisor process). If the queue stalls, logs will be delayed or lost.
  • Do not enable this on development environments where queues are not processed automatically - logs will appear to be missing.

Can also be set in config/order-lifecycle.php to enforce it environment-by-environment:

php
'asyncLogging' => App::env('QUEUE_LOGGING') === 'true',

Data Collection

SettingDefaultDescription
Collect User IP AddresstrueStore the IP address of the user who triggered each event
Collect User IDtrueStore the logged-in user ID alongside each event

Disable these settings to reduce personally identifiable information stored in logs, in compliance with GDPR or similar privacy regulations.

Display

SettingDefaultDescription
Show Lifecycle Statistics WidgettrueShow the statistics dashboard widget

Log Pruning

SettingDefaultDescription
Auto-Prune Logs After (Days)0Automatically delete logs older than this many days. 0 disables pruning. Maximum 365.

Pruning runs on the next request after midnight. You can also run it manually via the console:

bash
php craft order-lifecycle/logs/purge --days=90

Integrations

Anthropic API Key

Required to enable AI Insights. Generate a key at console.anthropic.com and add it to your environment:

ANTHROPIC_API_KEY=sk-ant-...

Set the Anthropic API Key field in Settings → Order Lifecycle → Integrations to $ANTHROPIC_API_KEY, or configure it in config/order-lifecycle.php:

php
'anthropicApiKey' => '$ANTHROPIC_API_KEY',

When configured, an AI Insights button appears in the Order Lifecycle field on every order, and the Order Lifecycle AI Insights dashboard widget becomes available. Leave this blank to disable all AI features.

AI Prompt Customisation

The prompts sent to Claude can be overridden in Settings → Order Lifecycle → Integrations → AI Prompt Customisation. Each field accepts free text with {placeholder} tokens that are substituted with live data before the request is sent. Leave a field blank to use the built-in default.

SettingDescription
Per-Order Insights PromptPrompt used when the AI Insights button is clicked on an individual order
Store Insights PromptPrompt used by the dashboard AI Insights widget

Can also be set in config/order-lifecycle.php:

php
'orderInsightsPrompt' => 'Your custom prompt with {total}, {eventTimeline}, etc.',
'storeInsightsPrompt' => 'Your custom store prompt with {days}, {conversionRate}, etc.',

See the AI Insights guide for the full list of available tokens for each prompt.

Console Commands

The plugin provides console commands for log management independent of the CP settings:

bash
# Delete logs older than 90 days
php craft order-lifecycle/logs/purge --days=90

# Dry run (shows count without deleting)
php craft order-lifecycle/logs/purge --days=90 --dry-run

# Delete logs for orders that no longer exist (deleted or trashed)
php craft order-lifecycle/logs/purge-orphaned

# Dry run orphan cleanup
php craft order-lifecycle/logs/purge-orphaned --dry-run

# Show log statistics
php craft order-lifecycle/logs/stats

# Optimise the logs database table
php craft order-lifecycle/logs/optimize

Garbage Collection

The plugin integrates with Craft's built-in garbage collection. When php craft gc/run executes, the plugin automatically removes lifecycle logs for orders that have been deleted or moved to trash. This appears as:

> deleting orphaned order lifecycle logs ... done

This runs automatically alongside all other Craft GC tasks. No additional configuration is needed.

Lifecycle logs are also removed immediately when an order is deleted (via Commerce's cart purge, manual deletion, or emptying the Craft trash). GC serves as a safety net for any that are missed.