Skip to content

fix(order-lines): resolve purchasable relationship for ShippingOption lines#2506

Open
bpotmalnik wants to merge 1 commit into
lunarphp:1.xfrom
bpotmalnik:fix/shipping-order-line-purchasable-relationship
Open

fix(order-lines): resolve purchasable relationship for ShippingOption lines#2506
bpotmalnik wants to merge 1 commit into
lunarphp:1.xfrom
bpotmalnik:fix/shipping-order-line-purchasable-relationship

Conversation

@bpotmalnik
Copy link
Copy Markdown
Contributor

@bpotmalnik bpotmalnik commented May 29, 2026

Fixes #2294

Accessing $orderLine->purchasable on a shipping line threw a fatal error
because Eloquent tried to instantiate ShippingOption as a model with no
arguments, but it is a plain DTO with required constructor parameters.

I've added a getPurchasableAttribute() accessor that detects purchasable_type of
ShippingOption and reconstructs the DTO from the snapshotted order line
data (description, identifier, unit_price, option, meta) instead of
querying the database. All other purchasable types fall through to the
normal morphTo relationship unchanged.

description: (string) $this->description,
identifier: (string) $this->identifier,
price: $this->unit_price,
taxClass: TaxClass::getDefault(),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made it use default as taxClass property is not nullable and there is no tax_class_id stored on order_lines (as every detail is captured on $orderLine->tax_breakdown).

Copy link
Copy Markdown
Contributor Author

@bpotmalnik bpotmalnik May 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about DX and how to inform dev about that this taxClass might be not accurate representation of what is in tax_breakdown, but I did not find right place for comment.

I think also rather than returning ShippingOption, it could return ShippingLineSnapshot that could be more accurate object (as it is already not real model class stored in db.

… lines

Fixes lunarphp#2294

Accessing $orderLine->purchasable on a shipping line threw a fatal error
  because Eloquent tried to instantiate ShippingOption as a model with no
  arguments, but it is a plain DTO with required constructor parameters.

Add a getPurchasableAttribute() accessor that detects purchasable_type of
  ShippingOption and reconstructs the DTO from the snapshotted order line
  data (description, identifier, unit_price, option, meta) instead of
  querying the database. All other purchasable types fall through to the
  normal morphTo relationship unchanged.
@bpotmalnik bpotmalnik force-pushed the fix/shipping-order-line-purchasable-relationship branch from fa4c61d to ce5042b Compare May 29, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

ShippingOption error when accessing purchasable relationship of OrderLine

1 participant