-
Notifications
You must be signed in to change notification settings - Fork 455
Description
- Lunar Version: 1.0.1
- Laravel Version: 12.26.4
- PHP Version: 8.4.10
- Database Driver & Version: PostgreSQL 17.5
Expected Behaviour:
When a cart is updated and createOrder() is called again, the resulting draft order should exactly mirror the current state of the cart.
If an existing order line no longer matches any line in the cart (for any reason), it should be removed — ensuring the order totals, lines, and breakdowns remain consistent with the cart.
This is expected behaviour since both cart_lines and order_lines in Lunar support rich attribute data (including meta), allowing equality to be determined across all relevant fields.
Actual Behaviour:
The cart correctly contains only the intended, up-to-date line(s) and recalculates totals accurately.
However, the order retains outdated order lines from a previous draft even after those lines have been removed or changed in the cart.
This occurs because:
CreateOrderLinesdetermines equality usingArr::diff()across all relevant line attributes.CleanUpOrderLinesonly filters bypurchasable_idwhen removing stale lines.
As a result, old order lines that differ in other attributes (e.g. configuration or customisation data) remain attached to the draft order, inflating totals and causing duplicates.
Steps To Reproduce:
- Add a product to the cart (e.g. a “Custom Engraved Mug”), along with engraving text stored as cart line meta, and proceed until an order is created (authorized) but not placed (captured) (
placed_at = null). - Return to the cart and update the same product with different attributes (e.g. change the engraving text or another property).
- Call
createOrder()again to regenerate the order. - Observe that:
- The cart contains only the updated line (correct).
- The draft order now contains both the old and new lines (incorrect).
Additional Context:
Both classes are part of the order creation pipeline:
Lunar\Pipelines\Order\Creation\CreateOrderLinesLunar\Pipelines\Order\Creation\CleanUpOrderLines
The former uses Arr::diff() to check all attributes for equality; the latter only checks purchasable_id.
Aligning their equality logic would ensure the draft order remains consistent with the cart state.
A call to cart->createOrder() occurs during payment authorization.
This approach follows Lunar’s own payment flow pattern, where an order is created prior to recording a transaction so that the payment intent or transaction can be correctly associated with the order record.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status