Custom Fulfillment Service. Not all product inventories update.

Solved
oldnightowl
Tourist
3 0 0

I have written a custom fulfillment service to provide timely inventory adjustments to our products. It works almost perfectly, however a few products are not updating correctly.

There are over 8500 products, 4 variants each. The vast majority correctly update their inventory when Shopify pulls updates from the callback url. eg https://myapp.com/fetch_stock.json

But, some products are stubborn and wont update inventory levels, even when deleted and re-created. Despite this, creating a different product works perfectly and inventory levels update immediately.

Notes:

  • The products that do not update, have not updated for over 72 hours.
  • All of the products in question have the same custom fulfillment service attached.

 

Things I have tried.

Toggle the fulfillment_service property on the product variants.

Result. Shopify requests the levels for SKUs of the product. My callback responds with the correct values. Shopify sets the levels at 0.

 

Delete the product and recreate it.

Result. Shopify requests the levels and ignores them, setting levels to 0.

 

Delete a working product and recreate it.

Result. Shopify requests the levels and correctly sets them.

 

Wait for the hourly all SKU request.

Result. Shopify requests all SKUs, my code responds with all SKU levels but Shopify does not update the products in question. It correctly updates the rest.

 

 

{
    "fulfillment_service": {
        "id": 99999999999,
        "name": "XXXXXXXXXXXXXXX",
        "email": null,
        "service_name": "XXXXXXXXXXXXXXX",
        "handle": "XXXXXXXXXXXXXXX",
        "fulfillment_orders_opt_in": false,
        "include_pending_stock": false,
        "provider_id": null,
        "location_id": 99999999999,
        "callback_url": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "tracking_support": false,
        "inventory_management": true
    }
}

 

I reached out to Shopify support and they directed me here as the issue was outside their scope.

I can provide Shop or product urls/json on request.

 

Any assistance would be greatly appreciated.

 

0 Likes
_JB
Shopify Staff
Shopify Staff
834 99 189

Hey @oldnightowl,

There's 2 things you can check:

- Make sure the SKU in question isn't being used on another product

- Make sure the SKU in question doesn't exist on any unfulfilled orders in the store.

If those don't fix the issue, please provide a few example inventory_item_ids and I can check our logs for more details.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me 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

oldnightowl
Tourist
3 0 0

Thanks for the reply.

Good questions.

I can 100% confirm the product SKU is unique to that product.

 

However, there are unfulfilled orders outstanding on this product but I am unclear on why this would prevent inventory updates.

We sold several, then received another shipment.

inventory_item_id

34391719870558
34391719903326
34391719936094
34391719968862

inventory_quantity in order should be 24, 0, 0, 1 yet they all show in Shopify as 0.
0 Likes
_JB
Shopify Staff
Shopify Staff
834 99 189

This is an accepted solution.

Hey @oldnightowl,

Here's a little blurb about the fetch_stock endpoint's behaviour:

When Shopify makes a fetch_stock call to a store, Shopify also takes into account any units that are currently unfulfilled in the store.

For example, say a store had 10 units of a particular SKU and 2 were sold. Those 2 units haven't been shipped yet, so they're just sitting on the pending unfulfilled orders in the store. When Shopify does a fetch_stock for this SKU, we expect your response to be 10 (since you haven't shipped the items, we expect 10 of them to be at your warehouse). When Shopify gets a response of 10, the pending unfulfilled units are subtracted, and in this case the inventory quantity displayed to the merchant is 8 (which is the actual number they have available for sale).

The important thing to note here is that you don't need to account for pending_unfulfilled orders when responding to fetch_stock. Shopify decrements inventory from the fulfillment service when an order is actually fulfilled, so you need to ensure you only decrement inventory when fulfillments are created, and otherwise respond to the fetch_stock call with your current inventory level.

 

I checked the inventory_item examples you provided, and the behaviour described above explains the numbers you're seeing. For example, I checked the item 34391719870558 which should have 24 units available, and I can see that SKU exists on many existing orders in the shop. You can delete/fulfill these orders, and then you will see the number from your response displayed as the available quantity in the admin. 

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me 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

oldnightowl
Tourist
3 0 0

Thanks for your explanation _JB

My current process is to immediately process Shopify sales through our backend systems, deducting from available inventory.

I will need to rethink the timing of this as it causes unfulfilled orders to be counted twice.

0 Likes
pjv0580
New Member
6 0 0

Hello _JB,

What you have is really a great description and should be added to the API documentation. However i am still not understanding this fully. My fulfillment service is used to manage inventory between two stores. so the same sku (asdf1234 for example) is sold on two stores. if i have 10 items on hand (in the warehouse) and i sell 2 in store A, and 1 in store B are you saying i need to keep track of each each stores sales in order to report how many are on hand relative to the store i am reporting for?  Using what you wrote if i just report 10 store A will only report 8 and store b will report 9. It seems to me that the fetch service should report what is available to sell not what is on hand.

I am also seeing something very different in my managed fulfillment service web hooks. i am seeing the inventory being consistently set back to 0 and the minuets later be set back to the actual number. can you explain this type of behavior. I tried contacting support on this and i was told to go to this forum.

here is an example from one product inventory history table

30 min. ago   Manually added   <MY APP> +24   20

35 Min. ago    Manually removed <My App> -24   0

1:44PM           Manually Added     <My App> +24   24

1:25PM           Manually Added     <My App> -27   0

1:09PM           Online Store            <My App> -1   27

so for all times the service was called it never returned a 0 value for this sku. but as you can see the 0 somehow gets reported then corrected.

any help would be appreciated.

 

 

 

 

 

 

0 Likes