Overview
The order history page allows authenticated customers to view their past orders, check order statuses, and review the details of individual orders. This guide walks through resolving the current customer, querying their orders, displaying a paginated order list, and building an order detail page. The examples below use standard Laravel controllers and Blade templates. The same concepts apply whether the storefront is built with Livewire, Inertia, or a headless API.Resolving the Current Customer
Lunar separates the concept of aCustomer from Laravel’s User model. An authenticated user can be linked to one or more customers through the LunarUser trait. The StorefrontSession facade provides the current customer for the session.
getCustomer() returns null. Protect account pages with middleware that checks for an authenticated user and a valid customer:
The
StorefrontSession automatically resolves the customer from the authenticated user when the LunarUser trait is applied to the User model. See the Storefront Session reference for details on how customer resolution works.Listing Orders
Query the customer’s orders using theorders relationship. Only orders with a placed_at value should be shown, as draft orders (where placed_at is null) have not been completed.
Displaying the Order List
Each order has its financial totals cast toLunar\DataTypes\Price objects, so formatted() can be called directly.
Order Financial Properties
After retrieval, eachLunar\Models\Order has the following price properties:
All values are
Lunar\DataTypes\Price objects with access to value (integer in minor units), decimal() (float), and formatted() (currency string).
Order Detail Page
The order detail page shows the full breakdown of a specific order, including line items, addresses, and totals.Displaying Order Lines
Order lines hold a snapshot of each purchased item. Thedescription field contains the product name at the time of purchase, and option holds any variant options.
Displaying Addresses
Each order stores a billing address and (for shippable orders) a shipping address. These are snapshots taken at the time of order creation and are separate from the customer’s saved addresses.Displaying Order Totals
Tax Breakdown
To display a detailed tax breakdown:Eager Loading for Performance
When displaying an order list, eager load the relationships needed for the list view to avoid N+1 queries:Routes
Putting It All Together
Here is a complete controller for the order history pages:Next Steps
- Review the Orders reference for the full list of order fields, relationships, and status configuration.
- Review the Customers reference for customer model details and the user-customer relationship.
- Review the Storefront Session reference for how customer resolution works.
- Review the Customer Addresses guide for building an address management page.