WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

CreateOrderLines and CleanUpOrderLines use inconsistent equality checks for order lines - resulting in stale order lines remaining on the order. #2328

@indygill

Description

@indygill
  • 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:

  • CreateOrderLines determines equality using Arr::diff() across all relevant line attributes.
  • CleanUpOrderLines only filters by purchasable_id when 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:

  1. 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).
  2. Return to the cart and update the same product with different attributes (e.g. change the engraving text or another property).
  3. Call createOrder() again to regenerate the order.
  4. 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\CreateOrderLines
  • Lunar\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

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions