Skip to content

Fix: Prevents fatal errors for custom Purchasable models#2306

Merged
glennjacobs merged 6 commits intolunarphp:1.xfrom
ablunier:1.x
Nov 11, 2025
Merged

Fix: Prevents fatal errors for custom Purchasable models#2306
glennjacobs merged 6 commits intolunarphp:1.xfrom
ablunier:1.x

Conversation

@ablunier
Copy link
Contributor

@ablunier ablunier commented Oct 3, 2025

This PR improves support for custom models that implement the Purchasable interface but are not standard ProductVariants.

Currently, using a custom purchasable can lead to two exceptions:

  1. DiscountManager error: It assumes the purchasable always has a ->product->collections relationship, causing a null pointer exception if it doesn't.
  2. Admin Panel error: The order details view assumes the purchasable has a getOptions() method, which is specific to ProductVariant.

This PR resolves these issues with minimal impact:

  1. The DiscountManager call chain is made null-safe to gracefully handle purchasables without product collections.
  2. The Purchasable interface now includes getOptions().

This makes the Purchasable interface more robust and truly extensible as intended. Any feedback is welcome.

@lunarphp lunarphp deleted a comment from vercel bot Oct 14, 2025
@glennjacobs
Copy link
Contributor

@ablunier it looks like we have failing tests. Are you able to take a look? Thanks.

@ablunier
Copy link
Contributor Author

Tests are now green @glennjacobs
Sorry!

@glennjacobs glennjacobs merged commit c8d464f into lunarphp:1.x Nov 11, 2025
44 checks passed
@glennjacobs
Copy link
Contributor

Thanks @ablunier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants