Skip to content

Conversation

@onbuyuka
Copy link
Contributor

@onbuyuka onbuyuka commented Jan 14, 2026

Summary

This PR improves the reliability of matching Shopify fulfillment order lines to Business Central sales shipment lines by using the Line Item Id directly from Shopify's API, instead of the previous matching logic based on variant, location, and delivery method type.

Problem

The previous implementation used a combination of Shopify Variant Id, Location Id, and Delivery Method Type to match fulfillment order lines. This approach was fragile and could fail in scenarios with:

  • Multiple order lines for the same variant
  • Split shipments across different fulfillment orders
  • Complex delivery configurations

Solution

  • Import and store Line Item ID: Fetch lineItem.legacyResourceId from Shopify's FulfillmentOrderLineItem GraphQL response and store it in the new "Line Item Id" field on the "Shpfy FulFillment Order Line" table
  • Direct matching: Match fulfillment order lines to order lines using the Line Item Id instead of variant-based matching
  • Handle split quantities: Loop through multiple fulfillment lines when a single order line is split across fulfillment orders

Changes

Schema Changes:

  • Added field "Line Item Id" (BigInteger) to "Shpfy FulFillment Order Line" table
  • Added Key4 on "Shopify Order Id", "Line Item Id" for efficient filtering

GraphQL Queries:

  • Updated ShpfyGQLOpenFulfillmOrdLines and ShpfyGQLNextOpenFFOrderLines to fetch lineItem.id (legacyResourceId)

Import Logic:

  • ShpfyFulfillmentOrdersAPI: Populate "Line Item Id" when importing fulfillment order lines
  • ShpfyImportOrder: Filter by "Line Item Id" instead of "Shopify Variant Id" in UpdateLocationIdAndDeliveryMethodOnOrderLine

Export Logic:

  • ShpfyExportShipments: Simplified CreateShopifyFulfillment by removing query-based location/delivery method grouping
  • Rewrote FindFulfillmentOrderLine -> FindFulfillmentOrderLines to handle multiple fulfillment lines per order line with quantity tracking
  • Removed LocationId and DeliveryMethodType parameters from CreateFulfillmentOrderRequest

Cleanup:

  • Deleted ShpfyShipmentLocation query (no longer needed after refactor)
  • Removed query permission from ShpfyObjects.PermissionSet.al

Testing

  • Updated ShpfyShippingHelper test helper to populate "Line Item Id"
  • Updated all test calls in ShpfyShippingTest to use the new CreateFulfillmentOrderRequest signature

Fixes AB#617896

@onbuyuka onbuyuka requested a review from a team as a code owner January 14, 2026 22:13
@github-actions github-actions bot added the AL: Apps (W1) Add-on apps for W1 label Jan 14, 2026
@github-actions github-actions bot added this to the Version 28.0 milestone Jan 14, 2026
- Remove ShpfyShipmentLocation.Query.al (no longer needed after refactor)
- Remove query permission from ShpfyObjects.PermissionSet.al
@onbuyuka onbuyuka changed the title Improve Fulfillment Order Line matching using Line Item ID [Shopify] Improve Fulfillment Order Line matching using Line Item ID Jan 14, 2026
if TempFulfillmentOrderLine.FindSet() then begin
GraphQuery.Append('{"query": "mutation {fulfillmentCreate( fulfillment: {');
if GetNotifyCustomer(Shop, SalesShipmentHeader, LocationId) then
if GetNotifyCustomer(Shop, SalesShipmentHeader, TempFulfillmentOrderLine."Shopify Location Id") then
Copy link
Contributor

Choose a reason for hiding this comment

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

If i read this right, connector populates TempFulfillmentOrderLine with all fulfilment lines that can be send to Shopify.
The next step - it iterates via lines and if line has different Fulfillment Order Id it will create new node with fulfillmentOrderId with fulfillmentOrderLineItems array.
As there is no sorting in the TempFulfillmentOrderLine there is a possibility that there will be multiple nodes with same fulfillmentOrderId but different content in fulfillmentOrderLineItems . Any risk that Shopify won't accept mutation that contains same fulfillmentOrderId ?

Scenario:
Order with Items:
A
B
C

Fulfillment Order1 with items A and C
Fulfillment Order2 with item B

Posted shipment with lines
A
B
C

So now connector will create mutation:
mutation {fulfillmentCreate( fulfillment:
..
{
fulfillmentOrderId = Fulfillment Order1 {fulfillmentOrderLineItems [A],
fulfillmentOrderId = Fulfillment Order2 {fulfillmentOrderLineItems [B],
fulfillmentOrderId = Fulfillment Order1 {fulfillmentOrderLineItems [C],
}

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

Labels

AL: Apps (W1) Add-on apps for W1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants