Skip to content

API Reference Overview beta

Order Lifecycle exposes a single service - OrderLifecycleLogger - plus a Twig variable for template-level access. There are no separate statistics or timeline service classes; all log retrieval is done through the logger.

Accessing the Service

php
use johnhenry\orderlifecycle\OrderLifecycle;

$logger = OrderLifecycle::getInstance()->logger;

Twig Variable

The plugin registers a craft.orderLifecycle Twig variable:

twig
{# Log checkout started (idempotent - safe to call on every page load) #}
{% do craft.orderLifecycle.logCheckoutStarted(cart) %}

{# Get the logger service from Twig #}
{% set logger = craft.orderLifecycle.getLogger() %}

Basic Usage

Logging a Custom Event

php
use johnhenry\orderlifecycle\OrderLifecycle;
use johnhenry\orderlifecycle\enums\EventType;

OrderLifecycle::getInstance()->logger->log(
    $order,
    EventType::STATUS_CHANGED,
    ['note' => 'Escalated by support'],
    'Order manually escalated'
);

Retrieving Logs for an Order

php
use johnhenry\orderlifecycle\OrderLifecycle;

$logs = OrderLifecycle::getInstance()->logger->getLogsForOrder($order->id);

foreach ($logs as $log) {
    echo $log['type'] . ': ' . $log['message'] . PHP_EOL;
}

Checking the Last Snapshot

php
use johnhenry\orderlifecycle\OrderLifecycle;

$snapshot = OrderLifecycle::getInstance()->logger->getLastSnapshot($order->id);

if ($snapshot) {
    $previousTotal = $snapshot['order']['totalPrice'];
}

Event Types

All event types are defined as cases on the EventType enum:

php
use johnhenry\orderlifecycle\enums\EventType;

EventType::CART_CREATED
EventType::LINE_ITEM_ADDED
EventType::ORDER_COMPLETED
EventType::PAYMENT_REFUNDED
// ... see Events reference for the full list

Next Steps