fix(order-lines): resolve purchasable relationship for ShippingOption lines#2506
Open
bpotmalnik wants to merge 1 commit into
Open
fix(order-lines): resolve purchasable relationship for ShippingOption lines#2506bpotmalnik wants to merge 1 commit into
bpotmalnik wants to merge 1 commit into
Conversation
bpotmalnik
commented
May 29, 2026
| description: (string) $this->description, | ||
| identifier: (string) $this->identifier, | ||
| price: $this->unit_price, | ||
| taxClass: TaxClass::getDefault(), |
Contributor
Author
There was a problem hiding this comment.
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).
Contributor
Author
There was a problem hiding this comment.
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.
fa4c61d to
ce5042b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.