Solved

Get product line item data from fulfillmentOrders line items

Rob-Widdick
Shopify Expert
10 0 3

I'm running into an interesting situation where when I query orders using GraphQL to get the fulfillmentOrders, I am unable to get the lineItems product data.

 

Here's an example query (some details removed/truncated):

 

{
  order(id: "gid://shopify/Order/12345") {
    currencyCode
    fulfillmentOrders(first: 10) {
      nodes {
        id
        status
        lineItems(first: 50) {
          nodes {
            id
            productTitle
            variantTitle
            totalQuantity
          }
        }
      }
    }
    lineItems(first: 50) {
      nodes {
        id
        currentQuantity
        quantity
        product {
          id
          title
m_reference: metafield(namespace: "m", key: "reference") {value}
m_color_code: metafield(namespace: "m", key: "color_code") {value}
}
variant {
sku
title
m_size_code: metafield(namespace: "m", key: "size_code") {value}
}
}
}
}
}

 

 

In this example above, I'm needing to grab metafield data from the underlying lineitem product and variant data.

 

However, the problem is that I need to do this while under the fulfillmentOrders object so because I'm looking at lineitems per fulfillment order. There's currently no way for me to know what the product details are for each line item while I'm iterating over each fulfillmentOrders order.

 

I'm unable to tie products together between order.fulfillmentOrders.lineItems to order.lineItems by SKU... and the "id" in order.fulfillmentOrders.lineItems is for the fulfillment Line Item ID, not the product ID.


Thoughts?

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1322 218 457

This is an accepted solution.

Hey @Rob-Widdick - great question, info and use-case here. Right out of the gate, not all resources are able to implement metafields - there is a complete list available here

FulfillmentOrder.lineItem and Order.lineItem reference different root objects, and their connection will be to independent LineItem objects; a good way to visualize this is through each gid (global identifier) structure. There isn't a direct relationship between those objects, rather a more indirect relationship that you may be able to map through the variant/product. While FulfillmentOrder.lineItem doesn't offer a full connection to the Variant or Product objects, productTitle and variantTitle can be returned on this object.

Working through a few test queries using our docs, my test app, and an API client (Insomnia), I was able to draft up an example query reworked from the one shared in your initial post. While querying for an order with the id as an argument, I have opted to also return the Order object through a connection on FulfillmentOrder, and then add in additional variant, product and metafields data from there. 

query getOrderAndFulfillmentOrderWithMetafields {
 order(id: "gid://shopify/Order/${order.id}") {
   fulfillmentOrders(first: 5) {
     nodes {
       id
       status
       order {
         lineItems(first: 10) {
           nodes {
             id
             sku
             variant {
               id
               title
               m_reference: metafield(namespace: "*", key: "*") {
                 value
                 type
                 ownerType
               }
               m_color_code: metafield(namespace: "*", key: "*") {
                 value
                 type
                 ownerType
               }
               product {
                 id
                 m_reference: metafield(namespace: "*", key: "*") {
                   value
                   type
                   ownerType
                 }
               }
             }
           }
         }
       }
       lineItems(first: 10) {
         nodes {
           id
           sku
           variantTitle
           productTitle
         }
       }
     }
   }
 }
}


Hope those insights help clarify and provide another approach towards you solution!

Cheers - @awwdam 
Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 3 (3)

Rob-Widdick
Shopify Expert
10 0 3

Also worth noting that I can't solely use order.lineItems because then I don't know what fulfillment order they belong to.

 

My goal would be to pull order.fulfillmentOrders.lineItems and see all relevant product/variant details that I need for our fulfillment.

ShopifyDevSup
Shopify Staff
1322 218 457

This is an accepted solution.

Hey @Rob-Widdick - great question, info and use-case here. Right out of the gate, not all resources are able to implement metafields - there is a complete list available here

FulfillmentOrder.lineItem and Order.lineItem reference different root objects, and their connection will be to independent LineItem objects; a good way to visualize this is through each gid (global identifier) structure. There isn't a direct relationship between those objects, rather a more indirect relationship that you may be able to map through the variant/product. While FulfillmentOrder.lineItem doesn't offer a full connection to the Variant or Product objects, productTitle and variantTitle can be returned on this object.

Working through a few test queries using our docs, my test app, and an API client (Insomnia), I was able to draft up an example query reworked from the one shared in your initial post. While querying for an order with the id as an argument, I have opted to also return the Order object through a connection on FulfillmentOrder, and then add in additional variant, product and metafields data from there. 

query getOrderAndFulfillmentOrderWithMetafields {
 order(id: "gid://shopify/Order/${order.id}") {
   fulfillmentOrders(first: 5) {
     nodes {
       id
       status
       order {
         lineItems(first: 10) {
           nodes {
             id
             sku
             variant {
               id
               title
               m_reference: metafield(namespace: "*", key: "*") {
                 value
                 type
                 ownerType
               }
               m_color_code: metafield(namespace: "*", key: "*") {
                 value
                 type
                 ownerType
               }
               product {
                 id
                 m_reference: metafield(namespace: "*", key: "*") {
                   value
                   type
                   ownerType
                 }
               }
             }
           }
         }
       }
       lineItems(first: 10) {
         nodes {
           id
           sku
           variantTitle
           productTitle
         }
       }
     }
   }
 }
}


Hope those insights help clarify and provide another approach towards you solution!

Cheers - @awwdam 
Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Rob-Widdick
Shopify Expert
10 0 3

Thank you for the answer! This makes sense and after some slight modifications on my end, this worked perfectly. I can now attribute line item details to fulfillment orders 🎉