Overview
Orders represent completed or in-progress purchases in a store. Orders are linked to carts, and although there is generally only one order per cart, the system supports multiple orders per cart if needed.All monetary values (such as
sub_total, total, tax_total) are cast to Lunar\DataTypes\Price objects, providing access to value, formatted(), and decimal properties.Fields
Relationships
Creating an Order
An order can be created directly or, the recommended approach, via aLunar\Models\Cart model.
allowMultipleOrders- Carts generally only have one draft order associated. Passtrueto allow multiple orders per cart.orderIdToUpdate- Optionally pass the ID of an existing draft order to update instead of creating a new one. The order must have a nullplaced_atvalue and belong to the cart.
Lunar\Actions\Carts\CreateOrder. This can be overridden in config/lunar/cart.php:
Lunar\Actions\AbstractAction:
Validating a Cart Before Creation
To check whether a cart is ready to create an order:Lunar\Validation\Cart\ValidateCartForOrderCreation class, which throws validation exceptions with helpful messages if the cart is not ready.
A custom validation class can be specified in config/lunar/cart.php:
Lunar\Validation\BaseValidator:
Order Reference Generation
By default, Lunar generates an order reference when creating an order from a cart. The format is:{0..0} indicates the order ID is padded to 8 digits (not including the prefix). The prefix is optional and defined in config/lunar/orders.php.
Custom Generators
To use a custom reference generator, updateconfig/lunar/orders.php:
null.
A custom generator must implement Lunar\Base\OrderReferenceGeneratorInterface:
Modifying Orders
To programmatically change order values or add new behavior, the order system can be extended. See Order Modifiers for more details.Order Status
Theplaced_at field determines whether an order is considered draft or placed. The Lunar\Models\Order model provides two helper methods:
Order Lines
Fields
Relationships
Creating an Order Line
Order Addresses
An order can have many addresses, typically one for billing and one for shipping.Fields
Relationships
Creating an Order Address
Shipping Options
To add shipping options, extend Lunar with custom logic. Shipping options can be fetched using theShippingManifest facade:
Lunar\DataTypes\ShippingOption objects.
Adding a Shipping Option to the Cart
Once a shipping option has been selected, add it to the cart so totals can be recalculated:Transactions
Fields
Relationships
Creating a Transaction
Most stores will want to store transactions against orders to track how much has been paid, the payment method used, and how to issue refunds if needed.Payments
Lunar is payment-provider agnostic. Any payment provider can be integrated with a storefront. The key factor for an order is whether theplaced_at column is populated. Everything else about payment handling is left to the store implementation. Lunar provides helper utilities (as described above) to manage the payment lifecycle.
Order Notifications
Lunar allows specifying which Laravel mailers and notifications should be available when updating an order’s status. These are configured inconfig/lunar/orders.php:
Mailer Template
When building a mailer template, the$order model is available in the view data. When the status is updated, the order is passed through along with any additional content entered. Since additional content may not always be present, check for its existence first.
Example template:
Order Invoice PDF
By default, clicking “Download PDF” in the admin panel when viewing an order generates a basic PDF. The view powering this PDF can be published for customization:resources/vendor/lunarpanel/pdf/order.blade.php that can be freely customized.