Skip to main content
A fulfilment is a unit of “getting the order’s goods to the customer” — a shipment, an in-store pickup, or a digital provisioning — tracked independently of payment.

Overview

An order’s fulfillableLines (lines where requires_fulfilment is true) are covered by one or more Fulfilment records. When an order is placed, Lunar automatically creates its initial fulfilments: each registered fulfilment method claims the lines it covers, in priority order, and a method that claims at least one line gets one fulfilment covering them. A basket of a shippable product, a licence key, and a click-and-collect item ends up with three fulfilments — one per method. A merchant does not create the initial fulfilment by hand; they split, merge, or move lines between the fulfilments that already exist. Each fulfilment progresses through a state graph owned by its method — a shipping fulfilment ships and can be returned, a digital one is provisioned, a pickup one is marked picked up. The order’s own fulfilment_status is a rollup over all of an order’s fulfilments and is method-agnostic.

Fulfilment model

Fields

Relationships

Scopes

Other useful methods

Fulfilment lifecycle

state is cast to a Lunar\Core\States\Fulfilment\FulfilmentState instance. Unlike the order’s derived payment_status/fulfilment_status, this is a hand-driven, guarded state machine — an illegal transition throws.
The state graph is owned by the fulfilment’s method, not a single fixed graph. Every state and transition contributed by any registered method is known to the underlying spatie/laravel-model-states machine (so it can cast any fulfilment’s state), but a per-method guard (MethodAwareTransition) enforces that a given fulfilment only ever follows its own method’s transitions — a collection fulfilment cannot move to Shipped even though that transition exists for shipping.
Every state belongs to a fixed rollup category — Outstanding, Fulfilled, Returned, or Cancelled — which is what the order-level fulfilment_status rollup and the split/merge/return mechanics reason over, regardless of method:

Per-method transition graphs

shipping (default state Pending, fulfilled state Shipped):
  • Pending → InProgress, Shipped, Cancelled
  • InProgress → Pending, Shipped, Cancelled
  • Shipped → Pending, Returned
  • Returned → Shipped
  • Cancelled is terminal
pickup (default state Pending, fulfilled state PickedUp):
  • Pending → ReadyForPickup, PickedUp, Cancelled
  • ReadyForPickup → Pending, PickedUp, Cancelled
  • PickedUp → Pending, Returned
  • Returned → PickedUp
  • Cancelled is terminal
digital (default state Pending, fulfilled state Provisioned):
  • Pending → Provisioned, Cancelled
  • Provisioned → Pending
  • Cancelled is terminal
Digital fulfilments have no return transition. Entering a Fulfilled-category state stamps shipped_at (unless already set); reverting from Fulfilled back to Outstanding clears it and deletes any tracking — the fulfilment was never really handed over.

Verb methods

Every fulfilment operation is a verb on the Fulfilment model, delegating to an action contract:
ship(), fulfil(), markReturned(), and transition() accept a trailing notify flag — when true (the default), a state change fires the notifications registered against it, see Notifications on fulfilment events.
split(), merge(), and moveLinesTo() only operate on fulfilments still in an Outstanding state — they reorganise quantities that have not yet been handed over, and never change the total fulfilled quantity.

Fulfilment methods

A fulfilment method is the registered driver that owns a fulfilment’s flow: its state graph, which order lines it claims, and whether it carries carrier tracking.
supports() asks the claim() rule of a single purchasable before the order exists, so a cart can offer only the methods that can fulfil a line. isAvailable() says whether the store can use the method right now, whatever the purchasable: pickup is available only while a location has accepts_pickup set, and the other core methods always are. requiresDelivery() says whether the method delivers to the customer, so its lines need a shipping option and address and count towards shipping rates. Core registers three, in packages/core/src/Drivers/FulfilmentMethods/: shipping and pickup support shippable purchasables, and digital supports purchasables that need fulfilment but aren’t shippable. Only shipping delivers. When an order is placed, lines stamped with a registered fulfilment_method at order creation get one fulfilment per method first, in that method’s default state. A pickup fulfilment is created at the order’s pickup_location_id, and other methods at the default location. The remaining lines go through claim(): methods claim lines in ascending priority order over a shrinking pool of unclaimed lines, so digital and pickup get first pick and shipping claims whatever is left.

Restricting a purchasable’s methods

Lunar\Core\Contracts\Purchasable::allowedFulfilmentMethods() returns the method keys a purchasable may use, or null for no restriction. A variant reads its fulfilment_methods column: ['pickup'] for a collection-only item, ['shipping'] for a drop-shipped one. A custom purchasable uses the Lunar\Core\Models\Concerns\RestrictsFulfilmentMethods trait, which returns null, or implements the method. A variant that isn’t shippable needs fulfilling only when its fulfilment_methods names a method: ProductVariant::requiresFulfilment() returns true for a shippable variant or for one with methods set. A licence key that staff provision by hand sets shippable to false and fulfilment_methods to ['digital'], so its order line gets a digital fulfilment. A variant with neither, such as an instant download, has nothing to fulfil. The panel and Filament variant forms show every registered method as one checklist. Ticking a method that supports a shippable variant, such as shipping or pickup, makes the variant shippable; ticking another kind, such as digital, makes it not shippable, and the two kinds can’t be mixed. Ticking nothing leaves the variant not shippable with nothing to fulfil. FulfilmentMethods::supporting($purchasable) returns the registered methods that support the purchasable, that it allows and that are available, keyed by key in priority order. The allow-list never adds a method the driver doesn’t support. An item restricted to methods that are all unavailable, such as a collection-only item when no location accepts pickup, can’t be added to a cart. The variant forms still list an unavailable method an item uses, marked as unavailable, so staff can see why. Manage the registry via the FulfilmentMethods facade:
A custom Lunar\Core\Contracts\FulfilmentMethodManifest implements both. The order’s fulfilment_status rollup and the partial fulfilment update email count a line as dispatched through dispatchedStateNames().

Creating fulfilments

Lunar creates an order’s initial fulfilments automatically when it is placed — no call is needed for the common case. To create an additional fulfilment by hand (for example, covering a subset of lines with a specific method), use the order’s createFulfilment() verb:
lines maps an order line ID to the quantity to cover. attributes['method'] defaults to shipping; location_id defaults to the store’s default location (creating one named Default if none exists yet). Before creating, the requested quantities are validated against how much of each line is still outstanding — a line’s quantity minus what its existing (non-cancelled) fulfilments already cover. Requesting more than is outstanding, or against a line where requires_fulfilment is false, throws.

Changing a fulfilment’s method

Once the order is placed, staff change how the goods are handed over by changing fulfilments. The order lines keep the method the customer requested.
changeMethod() moves outstanding quantities into a new fulfilment in the target method’s default state, and deletes the source if it ends up empty. $moves maps an order line ID to the quantity, as for split(), and null moves everything. It throws Lunar\Core\Exceptions\FulfilmentException when:
  • the fulfilment has been handed over. Only fulfilments in the Outstanding category can change.
  • the target method doesn’t support a moved line’s purchasable, so a collection-only item can’t be changed to shipping.
  • the target method delivers and the order has no shipping address.
  • the target method is pickup and the location doesn’t accept pickup.
A pickup defaults to the order’s pickup location while it still accepts pickup, then Location::defaultPickup(), and throws when the location doesn’t accept pickup. Core never charges or refunds the change. Refund part of the shipping charge with the refund composer, or take an extra payment with recordPayment().

Fulfilment lines

Fields

Relationships

A [fulfilment_id, order_line_id] pair is unique — a fulfilment carries at most one line row per order line.

Tracking

A fulfilment can carry several tracking references (a shipment split across boxes or carriers).

Fields

Relationships

Other useful methods

Add tracking through the fulfilment’s ship() or addTracking() verb rather than creating a FulfilmentTracking row directly, so tracking-number validation runs against the carrier:

Carriers

A carrier resolves service labels and tracking URLs for a shipping provider.
Core registers four, extending the abstract Lunar\Core\Shipping\Carriers\Carrier base (which implements URL-template substitution and pattern validation from two protected hooks): royal-mail, dpd, ups, fedex. Manage the registry via the Carriers facade:
A custom carrier extends the base class:

Holding a fulfilment

A pre-ship fulfilment (pending or in-progress) can be put on hold, blocking it from shipping until released:
Holding is orthogonal to the state graph — the fulfilment keeps its current state while held_at is set. Reasons come from the HoldReasons manifest, mirroring order cancel reasons:

Notifications on fulfilment events

ship(), fulfil(), markReturned(), and transition() fire a FulfilmentStatusUpdated event when the state actually changes, which sends any notifications registered against the new state’s key — unless the verb’s notify argument is false, or the transition was cancel() (fulfilment cancellation never notifies the customer; that is the order-level cancel() notification’s job). Lunar registers a default email for four of these states: shipped (Lunar\Core\Notifications\OrderShipped, with the fulfilment’s lines and tracking), ready-for-pickup (OrderReadyForPickup), provisioned (OrderProvisioned), and returned (ReturnReceived). picked-up, in-progress, pending, and the fulfilment-level cancelled state send nothing. See the Notifications reference for what each contains, how to customize the templates, and how to register a notification against a custom fulfilment state.