Inventory decremented twice - by Shopify and App

New Member
6 0 0

I have a client shop that is experiencing an inventory issue I cannot reproduce.

 

My app creates a Fulfillment service and manages it's own inventory (via the fetch_stock endpoint that Shopify calls).

 

I'm seeing inventory getting decremented twice, once by Shopify (expected) and once by my app (unexpected).

 

Here is a screenshot of the inventory history:

Screen Shot 2019-10-29 at 9.27.42 PM.png

 

In my own dev store, it only shows Shopify adjusting the inventory ("Online Store"), and I never see "Manually removed" from the app.

 

The fetch_stock endpoint is correctly returning available inventory, for example:

 

{"14975":20,"14978":16}

 

I've tried turning automatic fulfillment on and off in my test store, no difference.

 

Is there some setting or behavior I'm not aware of?

 

I'm pretty sure it's related to an order pending fulfillment, as my fetch_stock endpoint will return the count as if all orders have been fulfilled. I.e, if total original inventory = 10, item count pending fulfillment = 2, fetch_stock will return 8. I think it's supposed to still return 10.  However, I can't reproduce this theory on a test store.

 

Full test case to attempt reproduce:

Add product, inventory = 10

Checkout order for 1, order is still unfulfilled. Shopify decrements 1

Wait 1 hour, and/or toggle Track quantity on/off, verified fetch_stock is returning 9.

Expecting Shopify to report that my app decrements 1 more inventory, to prove my theory above, so I can go ahead and fix the fetch_stock endpoint. But inventory stays at 9.

 

0 Likes
New Member
6 0 0

In summary, it seems Shopify is calculating inventory differently on my clients store vs my store:

 

On clients store:

Inventory  = fetch_stock endpoint minus pending unfulfilled 

 

On my dev store:

Inventory = fetch_stock endpoint 

 

As explained in this thread: https://community.shopify.com/c/Shopify-APIs-SDKs/Product-Variant-Level-Lower-Than-Fetch-Stock-Endpo...

 

It makes sense why I need to change inventory on my end to only decrement stock after fulfillment, however if I did that change, then the inventory count on my test store would be incorrect (because my test store seems to ignore pending unfulfilled orders - and I've tripled checked that the fetch_stock endpoint is being called by Shopify)

0 Likes
Shopify Staff
Shopify Staff
31 4 6

Hey @Event-Ticketing,

 

When responding to fetch_stock requests, can you confirm if you're preforming any logic yourself to account for pending unfulfilled orders in the Shopify shop? Shopify already takes these orders into account when processing your response, so if you're also trying to account for this in your response as well it can result in inventory being decremented twice as you described. You shouldn't do any additional calculations on your end when responding to fetch_stock requests, and just respond with the quantity that's actually in stock at the fulfillment service location. 

 

For example:

12:00 : T-Shirt (managed by your app) has 20 stock

12:05 : 1 shirt is sold on the Shopify online store (Shopify stock 19 : Warehouse stock 20)

12:30: Fetch_stock request occurs, warehouse responds with qty 20. (Shopify has qty 19 in stock + 1 pending unfulfilled = 20 (no adjustment necessary))

12:50: Order fulfilled by warehouse (Warehouse stock now qty 19, Shopify stock also qty 19)

1:30: Fetch_stock request occurs, warehouse responds with 19. (Shopify has qty 19 in stock with 0 pending unfulfilled = 19 (no adjustment necessary))

 

In the above scenario, responding with qty 19 on the 12:30 fetch_stock (to account for the unfulfilled order) would result in 1 more item being decremented by your app. Since Shopify assumes you aren't accounting for pending unfulfilled orders on the shop, a response of 19 indicates that 1 item was removed outside Shopify, and so Shopify needs to decrement the quantity on our side by 1 more.

 

If your app is configured the same for your client's store and dev store, I would expect to see a similar behaviour on both. Are you subscribed to the same webhooks on the client's store and your dev store? If you're still seeing a behaviour that looks unexpected, please provide the shop_ids and approximate timeframes from when the actions were taken on the shop, and we can investigate further.

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
New Member
6 0 0

Hi JB,

 

Yes, I'm currently responding with 19 at the 12:30 mark in your example. This makes sense to me why I need to change it to respond with 20, but I'm not getting the same behavior on my dev store, and yes I've checked the logs to see the webhooks and fetch_stock endpoints firing.

 

Test store: gm-development-test-store.myshopify.com

October 30, 2019 at 12:31 pm EST

Order #1002 was placed. Order is still un-fulfilled

Screen Shot 2019-11-05 at 8.16.10 AM.png

 

Fetch stock endpoint: https://shopify.guestmanager.com/fetch_stock.json?max_retries=3&shop=gm-development-test-store.mysho...

Returns 9 for SKU 15227

 

I would expect this to cause Shopify to manually decrement the stock to 8 (so that I can reproduce the bug occurring on a client store), and implement the fix you've prescribed, by moving fulfillment/inventory adustment out of the orders/create webhook.

 

The test store is using the same app as the client (not the Dev/unpublished app)

 

Thanks.

0 Likes
Shopify Staff
Shopify Staff
31 4 6

Hey @Event-Ticketing,

 

I had a look at your test store order, and I'm not sure why that one didn't exhibit the same behaviour. From what I can see I would've expected the fetch_stock Shopify did after the order was placed to result in SKU 15227 being decremented to 8. Do you mind if I issue some API credentials on your test shop to test this out myself?

 

 

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
New Member
6 0 0

Sure, please do. I tested it on one of my other dev stores as well - and same behavior. So far I'm only seeing the 'expected' behavior on that client store.

0 Likes
Shopify Staff
Shopify Staff
31 4 6

Hey @Event-Ticketing,

 

I've completed my testing and can confirm the expected behaviour is happening on your test store. I created my own fulfillment service and saw the inventory number decrement again after placing an order for a product and adjusting my fetch_stock response by -1. I also made another test order using the same test product, and the inventory decremented by 1 as expected on that as well.

 

I checked our logs for your original test order, and I can see why this didn't work the first time. The test order was created at 12:31pm, and Shopify made a fetch_stock request at 1:25 pm which only included 2 SKUs in the response: GET response action=fetch_stock in 0.4528s {"14877":99,"14879":50}

 

Since this fetch_stock didn't include the variant on your test order, the stock wasn't updated accordingly. Now that your endpoint includes the variant in question, this should work as expected on a new test order with your fulfillment service. If you'd like to test that, please adjust the fetch_stock response and make another test order, and adjust the fetch_stock again to match the quantity Shopify shows after your test order is placed. Don't hesitate to reach out if you run into any issues.

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
New Member
6 0 0

@_JB , wouldn't Shopify be fetching the stock every hour or so and eventually seeing the SKU in the response and adjusting the inventory accordingly? 

0 Likes
New Member
6 0 0

@_JB I created two more orders, and not seeing expected behavior.

 

First of all, after your test order, yes -1 was removed manually, but what about the first order at 12:31pm? There is no matching -1 adjustment for that.

 

Expectations:

- Original inventory was 10

- There are 5 completed, unfulfilled orders

- fetch_stock is returning 5

- Shopify should be showing out of stock, or 0/10 remaining

 

I'm not seeing any -1 Manually Removed adjustments for the orders I create via the Online Store, or Admin. Somehow you got it to trigger the -1 behavior (Order 1004, but I couldn't for either Order 1002, 1005, 1006

0 Likes
Shopify Staff
Shopify Staff
31 4 6

Hey @Event-Ticketing,

 

For the 2 test orders you created, one adjustment was made at 3:26pm for order 1006. I'm checking our logs and the number being returned for this SKU on fetch_stock requests keeps changing, so the system is only adjusting when the number returned is greater than the number Shopify shows+ pending unfulfilled. Here's the timeline:

 

11:36 am- I created order #1004, which decremented the quantity in Shopify to 8

12:26 pm- Fetch_stock occurs. Your response = qty 8. Shopify = qty 8+ 1 pending unfulfilled. Inventory in Shopify decremented to 7.

2:38 pm- Order #1005 created, inventory in Shopify decremented to 6.

2:50 pm- Order #1006 created, inventory in Shopify decremented to 5.

3:25pm- Fetch_stock occurs. This time, your response returned qty 6 for this variant. Shopify had 5+2 pending unfulfilled so 7. Since your response returned qty 6, Shopify decremented by 1 to bring the variant to it's current stock level of 4.

 

With regards to your expectations, keep in mind that Shopify only accounts for the pending unfulfilled orders once. Once an adjustment is made to account for a pending_unfulfilled unit, we don't make that adjustment again on future fetch_stock calls.

 

At this point it's difficult to say why this didn't work as expected on the original test order, but since our logs show inconsistent responses on the initial fetch_stocks after that order was placed, I recommend testing from scratch on a new variant. If you can setup a new variant or remove these test orders and reset the stock from the variant we've been testing with, I can verify in our logs that the fetch_stock response matches expectations and we should see the expected behaviour. If we don't see the expected behaviour, a new example will allow us to investigate further by being aware of any pending unfulfilled orders for that variant.

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes