Flow to check Specific Warehouse for when a product sells out

Topic summary

A Shopify Plus user is trying to create a Flow that sends email notifications when a product sells out completely at a specific warehouse (AU or NZ), but is receiving duplicate emails for both warehouses.

Initial Problem:

  • The Flow triggers on ‘Product variant inventory quantity changed’
  • Condition checks were returning true for both warehouses because location names and inventory values for all warehouses appear in arrays
  • Separate flows for each warehouse still resulted in multiple emails

Solution Development:
Paul_n identified that the condition logic needed to check both location name AND inventory quantity at the same nesting level within the inventory item array, rather than checking them independently.

Current Challenge:
The user wants emails only when ALL sizes/variants are sold out at a specific location, not when individual sizes sell out. However, there’s no built-in field for total inventory per location (only product.totalInventory which spans all locations).

Proposed Workaround:
Paul_n provided a custom code solution using the Run Code action that:

  • Loops through all product variants
  • Sums inventory levels for a specific location
  • Returns total inventory for both the product and specific variant at that location

The user hasn’t yet tested the code solution.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

Hello All,

I’m struggling with a flow that would let me check a specific warehouse on the event of ‘Product variant inventory quantity changed’.

I have two flows that are almost identical, with the only difference being the name of said warehouse.

Here’s my flow:

Ideally, this flow would sent me an email when an ACTIVE item in the AU Warehouse sells out. I have the same flow for the NZ Warehouse. Originally, the flow had conditions to check each warehouse, but I always received an email for both. As part of troubleshooting, I seperated the warehouse checks into individual flows, but I still get two emails, one for each warehouse.

When checking Recent runs, I see this:

Am I right is seeing that this condition will always be true for either warehouse, as both warehouse names are returned in the ‘location / name’ array? If so, that appears to defeat the purpose of specifying the warehouse name to begin with.

On top of that, the check for inventory also appears to have the stock values for both warehouses too:

I get two emails everytime there’s a zero in the above check, and sometimes I get four. I’m at a loss and if anyone can point me in the right direction, it would be greatly appreciated.

Kind regards,

Nathan

You need to check the name of the location and the inventory in the same condition. In this workflow, you just loop over the same list of locations twice and check those things independently. If you search for “location inventory” in the template library, you’ll find an example of what this looks like

Hi Paul,

Thanks for the reply. As suggested, I modified each flow to look like this:

As part of the test, the NZ warehouse has no stock of my test item. I manually drop the stock in the AU warehouse to zero but both flows run and I get two emails. This also happened when my original flow had the two ‘check ifs’, one for each warehouse. Do I need to also check ‘Inventory quantity prior’?

Regarding the template library, ‘location inventory’ has 31 results, and the closest fit was this flow:

“Send Slack message when variant inventory is out of stock at a certain location”

This was the flow I started with and modified. Is this the one you’d recommend?

Kind regards,

Nathan

your condition show look something like this:

You could check the location ID instead of the name. You need to be checking the inventory and location on the same inventory level item…the nesting level is very important.

Hi @paul_n ,

Thanks for the above. This is my new flow:

Initial testing on one product appeared to work, so I’m going to see if I can combine the flow so that after the product variant inventory changes, there are two check-ifs, one for each warehouse.

Question though - when the inventory is being queried, is that the total inventory for the product, or is it the total inventory for each of the product variants/sizes?

Kind regards,

Nathan

Ok so… I think one of the checks above is checking product inventory of a size/variant level, not the overall stock for the product.

Example:

An order was placed for a long sleeve shirt in red. The order was for a medium size. The flow triggered as there is no stock for the large.

Is there to check both the location and Product.totalInventory?

Thanks again,

Nathan

product.totalInventory is the total across variants and locations. Not clear what total you want.

What I’m hoping to achieve is have an email sent when a product is fully sold out of all sizes in a particular warehouse only.

Is there a product.totalInventory equivalent for specific location? I use product.totalInventory in another flow to let me know when a product is sold out in all warehouses and that works well.

My current flow above sends emails whenever a specific size sells out, or detects that a size was sold out. I need it to only send the email when the product is sold out of all sizes, not just one.

Is that possible?

Kind regards,

Nathan

No, that field doesn’t exist. You could need to check the quantity per variant / location and then total them up. You could do that in Run code by looping over the inventory levels for the variants.

Thanks @paul_n .

I’ll have a hunt around the forum to see if I can find an example of that. If you know of any and can point me in that direction, that would be awesome too.

Thanks for all your help! :slightly_smiling_face:

This one is kind of close. Same idea but different variables:
https://github.com/Shopify/flow-code-examples/blob/main/run-code-examples/order-sum-products/index.js

export default function main(input) {
  // Make sure that the data you return matches the
  // shape & types defined in the output schema.

  var inventory_product = 0;
  var inventory_this_variant = 0;
  input.product.variants.forEach(variant => {
    const amount = variant.inventoryItem.inventoryLevels.find(level => level.location.name == "YOUR LOCATION NAME").available;  
    inventory_product += amount;
    if(variant.id == input.productVariant.id) {
      inventory_this_variant += amount;
    }
  });
  
  return {
    inventoryProduct: inventory_product,
    inventoryVariant: inventory_this_variant
  }
}

Input

query{
  productVariant {
    id
  }
  product {
    variants {
      id
      inventoryItem {
        inventoryLevels {
          available
          location {
            name
          }
        }
      }
    }
  }
}

Output

"The output of Run Code"
type Output {
  "The message returned by the script"
  inventoryProduct: Int!
  inventoryVariant: Int!
}
1 Like

Hi @paul_n ,

Thanks for the above. I haven’t yet had the chance to test this yet, but will be in touch when I get the time :slightly_smiling_face:

Kind regards,

Nathan