Product Feed: How to get Online Store Availability ONLY

Highlighted
Tourist
9 0 3

Hey!

Running into a strange snag here: We are generating custom product feeds, and are checking availability based on a combination of three conditions which are all available in the products JSON for each product.

The fields we use are inventory_policy, inventory_management and inventory_quantity.

The problem we are facing is that inventory_quantity shows the total of all sales channels that keep inventory. So if the Online Store channel is out of stock, and another sales channel still has inventory, availability would show as "in stock". We want to show "in stock" only if the Online Store channel has inventory

The inventory API seems like it would provide the needed information, but it's quite complicated to pull in the additional information from there for each variant in the feed.

Am I missing something simple here?

Thanks for your help! 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
79 8 11

Hey @power777,

As you're aware, inventory_quantity is an aggregate of inventory across all locations. I assume you have one or more fulfillment services expected in inventory_management?

When a fulfillment service is created on a store by an app, Shopify automatically creates a location that's associated with that fulfillment service. You'll need to drill down into the InventoryLevels for your InventoryItems, filter out the Location associated with the sales channels that are not associated with the Online Store, and then sum the total of all appropriate InventoryLevels to display in place of inventory_quantity.

More docs herehttps://shopify.dev/docs/admin-api/rest/reference/inventory/inventorylevel?api[version]=2020-07

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

0 Likes
Highlighted
Tourist
9 0 3

Thanks CalD!

 

It seems like there must be a simpler solution for this as we can see feeds that are generated via simple template and liquid-merge fields are showing the correct availability. I don't think you can drill down into inventory levels for different locations for that, or can you?

 

Another problem with creating a generic solution via inventory levels is that the merchant can name the locations anything they want, and there is no way to even know which one is their "Onine Store" location.

 

Cheers,

Thomas

 

0 Likes
Highlighted
Shopify Partner
667 47 134

As far as I know the customer can't rename hard-coded sales channels, such as Online Store or Shopify POS. Even the new sales channels they might add, even if their titles change, the sales channel ID itself doesn't change once it's first created.

If you bear with me, you can use the GraphQL to first pull all sales channel ID's with their current titles. Like this example, where I am pulling the first 10 sales channels (aka publications):

 

{
  publications(first: 10) {
    edges {
      node {
        id
        name
      }
    }
  }
}

 

When the results are parsed we then have the ID's and display names. Let's say that we see the "Online Store" has an ID of gid://shopify/Publication/561264. Now that we have this value we can then query all products associated with this specific sales channel. Like this example, where I am pulling the first 10 products along with each product's first 10 variants:

 

{
  publication(id: "gid://shopify/Publication/561264") {
    products(first: 10) {
      edges {
        node {
          id
          title
          variants(first: 10) {
            edges {
              node {
                id
                title                
              }
            }
          }
        }
      }
    }
  }  
}

 

 I didn't see a way where we can use GraphQL to query against a specific sales channel's display name to retrieve all products, so this example is two-step process. Of course if you need to retrieve all products and variants you'd need to include paginated query parameters or else use bulk operations. But this is a start!

0 Likes