Re: Flow to check Specific Warehouse for when a product sells out

Flow to check Specific Warehouse for when a product sells out

n8churrr
Shopify Partner
23 1 5

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:

 

n8churrr_0-1739229053177.png

 

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:

 

n8churrr_1-1739229421421.png

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:

 

n8churrr_2-1739229830527.png

 

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

Replies 12 (12)

paul_n
Shopify Staff
1778 195 416

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

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
n8churrr
Shopify Partner
23 1 5

Hi Paul,

 

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

n8churrr_0-1739308588812.png

n8churrr_1-1739308808367.png

 

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"

n8churrr_3-1739319668402.png

 

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

 

Kind regards,

Nathan

 

paul_n
Shopify Staff
1778 195 416

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.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
n8churrr
Shopify Partner
23 1 5

Hi @paul_n,

 

Thanks for the above. This is my new flow:

n8churrr_0-1739389327829.png

 

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

n8churrr
Shopify Partner
23 1 5

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

paul_n
Shopify Staff
1778 195 416

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

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
n8churrr
Shopify Partner
23 1 5

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

paul_n
Shopify Staff
1778 195 416

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.

 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
n8churrr
Shopify Partner
23 1 5

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! 🙂

paul_n
Shopify Staff
1778 195 416

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.j...

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
paul_n
Shopify Staff
1778 195 416
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!
}
Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
n8churrr
Shopify Partner
23 1 5

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 🙂

 

Kind regards,

Nathan