Normalize order customer polymorphic type#236
Merged
Conversation
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.
Summary
Adds a FleetOps-side guard for order creation so customer polymorphic types are always persisted as concrete FleetOps model classes instead of the abstract customer type. This prevents order creation from failing during created webhook payload generation when the client submits customer_type as fleet-ops:customer.
Root Cause
The order create request can include a selected customer relationship whose Ember model is the abstract customer model while the actual record is a contact or vendor. When customer_type arrives as fleet-ops:customer, FleetOps converts that polymorphic type into Fleetbase FleetOps Models Customer. That PHP model does not exist. The order insert can complete, but the created model event builds the webhook payload, touches the Order customer morph relation, and Laravel throws Class Fleetbase FleetOps Models Customer not found.
This PR complements the fleetops-data serializer fix by making FleetOps resilient to stale or generic internal order payloads.
Changes
Behavior Before
A payload like customer_uuid b1641199-12e4-4c1e-8459-9f2dd9101c47 with customer_type fleet-ops:customer could persist an invalid morph class. When the created webhook payload accessed this customer relation, Eloquent attempted to instantiate Fleetbase FleetOps Models Customer and crashed.
Behavior After
The order form submits the concrete customer type when a customer is selected. The backend also normalizes customer_type from customer_uuid before saving, so even a stale or generic internal payload is corrected to Contact or Vendor before the order model fires created lifecycle/webhook logic.
Verification
Notes
This branch intentionally commits only the order customer-type normalization files. The local worktree contains unrelated pre-existing changes in workflow, package, route form, and payments files; those were left uncommitted and out of this PR.