[releases/28.x][Shopify] Fix fulfillment service handling#6959
Open
onbuyuka wants to merge 2 commits intoreleases/28.xfrom
Open
[releases/28.x][Shopify] Fix fulfillment service handling#6959onbuyuka wants to merge 2 commits intoreleases/28.xfrom
onbuyuka wants to merge 2 commits intoreleases/28.xfrom
Conversation
…ulfillment orders (#6904) When syncing shipments to Shopify, the `assignedFulfillmentOrders` GraphQL call fails with "The api_client is not associated with any fulfillment service" if the fulfillment service was disassociated on Shopify's side (e.g., app reinstall, store migration). ## Changes - **New GraphQL query** (`HasFulfillmentService`): Queries Shopify locations by name to verify the fulfillment service location exists before calling `assignedFulfillmentOrders`. - **`GetAssignedFulfillmentOrders`**: After the existing `Fulfillment Service Activated` flag check, queries Shopify to confirm the service actually exists. If not, resets the flag to `false` and exits gracefully. - **`ShpfySyncShipmToShopify`**: Tracks queried shop codes separately to avoid redundant API calls when a shop has no assigned fulfillment orders. Fixes [AB#623365](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/623365)
### Problem
When a fulfillment service location is deleted in Shopify but the
corresponding `Shpfy Shop Location` record still exists in Business
Central, the `GetLocation` GraphQL query returns
`{"data":{"location":null}}`. The code attempted to parse
`data.location.fulfillmentService` as a single path, which fails because
the null `location` token cannot be traversed to reach
`fulfillmentService`. This left a stale record with `Fulfillment Service
Id = 0`, causing `UpdateFulfillmentServiceCallbackUrl` to proceed with
an invalid ID in the `UpdateFulfillmentService` GraphQL mutation.
### Solution
**`GetFulfillmentService`**: Split the JSON parsing into two steps.
First resolve `data.location` — if it's null (location no longer exists
in Shopify), delete the stale `ShopLocation` record (which cascades to
related `Shpfy Shop Inventory` records) and exit. Then separately
resolve `fulfillmentService` within the location object.
**`UpdateFulfillmentServiceCallbackUrl`**: After calling
`GetFulfillmentService`, recheck `Fulfillment Service Id`. If it's still
`0` (record was deleted or service couldn't be resolved), exit before
attempting the update mutation. This provides defense in depth against
calling the Shopify API with an invalid ID.
Fixes
[AB#622988](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/622988)
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
Fixes AB#623993
Cherry-picked from main:
🤖 Generated with Claude Code