---
title: Overview
date: 2026-06-13T16:17:00+01:00
author: John Henry Donovan
canonical_url: "https://johnhenry.ie/plugins/order-lifecycle/docs/api/overview"
section: Plugins
---
esc

↑↓ to navigate↵ to selectesc to close

Menu On this page 

- [Return to top](#)

Documentation

Documentation

# Overview

Order Lifecycle exposes four services - `OrderLifecycleLogger` for reading and writing log entries, `StatsService` for store-wide metrics, `AiInsightsService` for Claude prompt building and generation, and `ExportService` for CSV export - plus a Twig variable for template-level access. See the [Services reference](https://johnhenry.ie/plugins/order-lifecycle/docs/api/services) for the full method list on each.

## Accessing the Service

```php
use johnhenry\orderlifecycle\OrderLifecycle;

$logger = OrderLifecycle::getInstance()->getLogger();
$stats = OrderLifecycle::getInstance()->getStats();
$ai = OrderLifecycle::getInstance()->getAiInsights();
$export = OrderLifecycle::getInstance()->getExport();
```

## 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() %}

{# Get the AI insights service, e.g. to detect whether a saved insight is
   structured JSON or narrative markdown before rendering it #}
{% set structured = craft.orderLifecycle.aiInsights.decodeStructuredInsights(savedInsights.message) %}
```

## Basic Usage

### Logging a Custom Event

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

OrderLifecycle::getInstance()->getLogger()->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()->getLogger()->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()->getLogger()->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

- [Services](https://johnhenry.ie/plugins/order-lifecycle/docs/api/services) - Full method reference for all four services
- [Events](https://johnhenry.ie/plugins/order-lifecycle/docs/api/events) - All `EventType` enum cases and what triggers them
- [Event Tracking Guide](https://johnhenry.ie/plugins/order-lifecycle/docs/guide/event-tracking) - Practical usage examples

On this page
