Location id for line items on order created event

Solved
abq
New Member
7 0 0

Hi

I have 2 locations setup (Location1 and Location2) in my Shopify webshop.

I have a web hook for order created, so that I can update the inventory levels in my system when that happens.

The problem is that I can't find a way to get from which location the line items are going to be fulfilled from. I am aware that if I fulfill the order, then there is another event that could be used (order fulfilled) but that is a bit to late in the process because I need to decrease the inventory levels straight away and not wait until the order gets fulfilled.

If you open an order in shopify admin, then you will see, let's call it, a preview from where the different items will be fulfilled from. That information is more or less exactly what I need.

I've looked at the line_items > origin_location but according to the documentation, this is not to be used for this purpose. You are referred to FulFillmentOrder but like I mentioned, fulfillments (can) happen way later.

I also notice that if you place an order with a single product that is only in stock at Location2, the information found in origin_location will still be from Location1.

Any ideas? Am I missing something?

I'm using the GraphQL API

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

I think this question might have come up not too long ago on here. Based on what I recall, something like this example below should list on-hand availability and fulfillment ability for each location. Give it a shot and let me know.

 

{
  product(id: "gid://shopify/Product/4452686168116") {
    variants(first: 10) {
      edges {
        node {
          id
          inventoryItem {
            id
            inventoryLevels(first: 5) {
              edges {
                node {
                  id
                  available
                  location {
                    id
                    name
                    fulfillsOnlineOrders
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 

0 Likes
abq
New Member
7 0 0

Do you mean that I should write the logic for how Shopify decides where line items are going to be fulfilled from?

I found the logic behind it on this page and it seems quite straight forward

https://help.shopify.com/en/manual/locations/setting-up-your-locations#set-the-priority-of-locations...

However, I'm not really keen on doing that sort of logic on my side because because I have no way of knowing if the logic changes on Shopify.

One upon a time there was a field in the order called draftFulfillments which is now deprecated and you are advised to use fulfillmentOrders instead. Which again isn't ideal for my use case.

To clarify my original post. The information that I am after is the one shown in the picture below. You see that Product 8004 is different location then Product 8005 but there doesn't seem to be anything in the GraphQL API that can provide these details, unless you mark the lines as fulfilled.

 

abq_0-1615904298142.png

 

 

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

The GQL query example I provided just shows the availability and fulfillability (not a real word) of a product's variants. But if Shopify has published their logic in terms of fulfillment priorities then the issue is they haven't exposed an API endpoint to access this? With that API endpoint being exposed you could then cross-reference things to determine the default fulfillment location for your product variants.

@HunkyBill any insight as to how you handle this?   

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

Here is the last discussion I've seen regarding this topic... https://community.shopify.com/c/Shopify-APIs-SDKs/Locations-API-fulfillment-priority/td-p/498105 

0 Likes
HunkyBill
Shopify Expert
4509 46 492

I am not sure why the OP is so dead set against fulfillmentOrders. When an order is booked, Shopify will go ahead and create assignedFulfillmentOrder objects, where the location from which to fulfill is apparently part of the internal setup of those. To compare contrast the OP approach with this one.

OLD SCHOOL: You wait for an order to be booked. Respond to Order webhook. Find out payload contains nothing useful about fulfillment, so now you cannot easily alter inventory, and you cannot wait for fulfillment to alter inventory. Conundrum.

NEW SCHOOL: You poll your open unfulfilled orders. For each one you find, look for the Shopify assignedFulfillmentOrder objects. Each contains some item that was sold and some glimmer of fulfillment information (locations/availability/quantities). So now you can shuffle your inventory numbers around based on the fulfillmentOrder information.

Not sure this is too clear, I have only limited real-world experience to go on here, as most of the time, I am dealing with the pattern of third-party fulfillment and fulfillment services that I create for WMS systems and drop shippers. When merchants incur the expense of having their own custom inventory management solutions, it is typical their use patterns are also bonkers compared to what I encounter. I have one merchant running two shops, each with three locations (each selling one inventory pile by the way), with each governed with its own inventory management system, and trust me, ensuring all three locations are in good shape, and propagating the numbers correctly between locations is a chore and subject to many questions. I got it working, but questions remain.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
abq
New Member
7 0 0

Thank you @HunkyBill and @Greg_Kujawa  very much for taking the time to answer.

Some background to my use case. We provide a POS system which has it's own inventory management functionality. When integration towards any external system, like Shopify, we made the choice of being the central hub of information, meaning if you were to do stock taking or getting a stock report, that would be done in our system. So when a product stock level is changed in our system, we will send the actual quantity that now holds true. (in the Shopify-case, you first need to get the stock level and then calculate and send the difference but it the result would be like sending the actual quantity)

One of our merchants have multiple locations but they do not have a centralized web storage meaning that web shop order are fetched from the sales floor. 

Their process (which I'm quite certain is very likely different between different merchants) is when a web shop order is received, it will show up on a computer screen and the staff would then go onto the sales floor and collect the items so that they don't run out of stock.

Here is the timing issue. When the web shop order is created would be the best time to get those items away from the sales floor because it might be that an order is fulfilled 24 hours after is is created. During which time, we will have somewhat of a discrepancy. 

However, I've spoken to my client and he confirms that this is actually not a very big problem. It's not very likely to run out of stock for most items and he would be fine handling it if it were to happen. The same client also mentions that as the web shop grows, he is going to set up a dedicated web storage facility where all web orders would be fulfilled from in the future but he is not really there yet.

Since there is no way of getting the location id from line items before it's fulfilled, then we will simply switch to listening for order fulfilled events instead of order created events for those merchant with multiple locations. Merchants with single location will still use order created events to adjust inventory levels.

Of course the best solution would still be that line items would contain location id, even if it's just a preview that could be altered during the fulfillment process because that would mean the admin who fulfills the orders would manually alter the order during the process.

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

Thanks for the thorough rundown of your scenarios! I would think in the case of those online web sales you could setup a webhook for them. Take the webhook, use that as a notification for local staff to physically pull the item out of stock, and then hit the GQL fulfillment endpoints that HunkyBill referred to. Thereby flagging those sold items as being fulfilled but not shipped. Or am I missing something? 

 

0 Likes
abq
New Member
7 0 0

I think I might have misunderstood.

From what I can tell, assignedFulfillmentOrder is reached from Shop

https://shopify.dev/docs/admin-api/graphql/reference/store-properties/shop#assignedfulfillmentorders...

Going through the example you see that you need to have the id for the FulfillmentOrder, which there are none in the Order-object.

How can I get assignedFulfillmentOrder(s) from only providing the order id?

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

This is an accepted solution.

@abq if you are looking to pull fulfillment order details that are present for an existing order that's been created, this example below would allow you to pull the info based on the order ID. Does this help?

{
  order(id: "gid://shopify/Order/THE_ORDER_ID") {
    name
    fulfillmentOrders(first: 5) {
      edges {
        node {
          id
          lineItems(first: 5) {
            edges {
              node {
                lineItem {
                  id
                  title
                  quantity
                  discountedUnitPriceSet {
                    shopMoney {
                      amount
                    }
                  }
                  fulfillmentService {
                    id
                    location {
                      id
                      name
                    }
                    serviceName
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
0 Likes