Can the order routing function route to a location that has inventory zero for the line item?

We have an order routing function where we’re routing the whole order to a single warehouse in certain situations.

It seems to work correctly when we have a non-zero inventory level in the warehouse in question for both products.

But when one product has inventory zero in that warehouse, it doesn’t work. We have Continue selling when out of stock set.

This is an example of a run where it tried to rank the LA warehouse higher than the NC warehouse:
https://partners.shopify.com/411398/apps/193114112001/extensions/function/896789217281/runs/07839030-72ba-499d-aab3-8564d0b74f24

{
  "cart": {
    "lines": [
      {
        "merchandise": {
          "id": "gid://shopify/ProductVariant/41882367033462",
          "sku": "",
          "title": null,
          "product": {
            "id": "gid://shopify/Product/7634763874422",
            "title": "LOCATION-RULE TESTING - Product in Both - 0 in LA, 10 in HP"
          },
          "losAngeles": {
            "value": "0"
          },
          "northCarolina": {
            "value": "10"
          }
        }
      },
      {
        "merchandise": {
          "id": "gid://shopify/ProductVariant/41882366902390",
          "sku": "",
          "title": null,
          "product": {
            "id": "gid://shopify/Product/7634763743350",
            "title": "LOCATION-RULE TESTING - Product in Both - 10 in LA, 0 in HP"
          },
          "losAngeles": {
            "value": "10"
          },
          "northCarolina": {
            "value": "0"
          }
        }
      }
    ]
  },
  "fulfillmentGroups": [
    {
      "handle": "1",
      "inventoryLocationHandles": [
        "67514007670",
        "67514040438"
      ],
      "lines": [
        {
          "merchandise": {
            "id": "gid://shopify/ProductVariant/41882367033462",
            "product": {
              "id": "gid://shopify/Product/7634763874422",
              "title": "LOCATION-RULE TESTING - Product in Both - 0 in LA, 10 in HP"
            }
          }
        }
      ]
    },
    {
      "handle": "2",
      "inventoryLocationHandles": [
        "67514007670",
        "67514040438"
      ],
      "lines": [
        {
          "merchandise": {
            "id": "gid://shopify/ProductVariant/41882366902390",
            "product": {
              "id": "gid://shopify/Product/7634763743350",
              "title": "LOCATION-RULE TESTING - Product in Both - 10 in LA, 0 in HP"
            }
          }
        }
      ]
    }
  ],
  "locations": [
    {
      "handle": "67514007670",
      "name": "High Point, NC",
      "address": {
        "city": "***",
        "countryCode": "US"
      }
    },
    {
      "handle": "67514040438",
      "name": "Los Angeles, CA",
      "address": {
        "city": "***",
        "countryCode": "US"
      }
    }
  ]
}

Result:

{
  "operations": [
    {
      "rank": {
        "fulfillmentGroupHandle": "1",
        "rankings": [
          {
            "locationHandle": "67514040438",
            "rank": 0
          },
          {
            "locationHandle": "67514007670",
            "rank": 1
          }
        ]
      }
    },
    {
      "rank": {
        "fulfillmentGroupHandle": "2",
        "rankings": [
          {
            "locationHandle": "67514040438",
            "rank": 0
          },
          {
            "locationHandle": "67514007670",
            "rank": 1
          }
        ]
      }
    }
  ]
}

But the order ended up split between the two warehouses:

The reason we want to route to a warehouse even when it has zero stock is so we can fulfill against future stock it will have and keep shipping cost low for the customer.

Also our location routing rule is the only order routing rule configured in order routing.

1 Like

Could you please check the default order routing strategy in the store settings?

If the Minimize split fulfillments rule is configured, it optimizes for fulfilling the order in the fewest number of packages. Locations that have all items in stock are prioritized over those that don’t.

When none of your locations have all the items in stock, this rule prioritizes locations that result in the fewest number of packages. Therefore, if both items are not available in the same location, the shipment will be split. The default rule is likely the reason for this behavior.

Please refer the default order routing rule: https://help.shopify.com/en/manual/fulfillment/setup/order-routing/understanding-order-routing

This is the only rule configured.

Also, please check if the Split shipment option is active or not.

Hi @AMaL , that is an unrelated setting which takes the results from the order routing logic, and determines how the relevant shipping methods are presented to the customer.

Shipping is split when products in an order are fulfilled from different locations or belong to separate shipping profiles. Customers will be able to select the shipping method for each shipment separately.

Sorry for the inconvineance. Yes you are right that realted to the shipping methods. Regarding order routing could you please confirm your store support order routing custom API.

Yes @AMaL , it does.

Can you please ensure that the IDs are in the Global ID structure format?


Example:

"fulfillmentGroupId": "gid://shopify/FulfillmentGroup/1"
"locationId": "gid://shopify/Location/1234567890"

Please refer the doc:

The API documentation, FulfillmentGroupRankedLocations, and the tutorial, Build a location rule function, both detail FunctionRunResult referencing Handles – fulfillmentGroupHandle

The output.json example on Order Routing Location Rule API reference is the only reference to FunctionRunResult referencing IDs – fulfillmentGroupId

The example cited appears inconsistent with the detailed documentation.

I believe that if the line item quantity is not fully available at the 0th-ranked location, Shopify will check the next location in the order, and so on. If the full quantity is not available at any location, it will be fulfilled at the 0th-ranked location. Otherwise, it will fulfill from the location where the full quantity is available (based on the rank).

{
  "operations": [
    {
      "rank": {
        "fulfillmentGroupHandle": "1",
        "rankings": [
          {
            "locationHandle": "67514040438",
            "rank": 0
          }
        ]
      }
    },
    {
      "rank": {
        "fulfillmentGroupHandle": "2",
        "rankings": [
          {
            "locationHandle": "67514040438",
            "rank": 0
          }
        ]
      }
    }
  ]
}

Could you please try using a single location in a fulfillment group to test this behavior?

I had a feeling this might be the case. This would be a blocker for our use case specifically because they want to route to the warehouse when it has zero inventory because the delivery time can be extended out into the future when it gets inventory.

Wouldn’t that also suggest that the documentation here, Order Routing Location Rule API reference, is incorrect, given we only have a single location-rule function operating in this store?

Combining fulfillment groups ranked locations from multiple functions

For each fulfillment group, Shopify first sorts the output of each function based on the locationRule priority. Shopify then takes the first output, and sorts the locations of the fulfillment group based on the rank. If there are ties between the rankings, then Shopify breaks them using the ranks from the second output, and so on. If there are no ties, then only the output of the first locationRule is considered.

1 Like

Can you use a variant metafield that contains the location name and inventory quantity? The metafield should be synced with the variant inventory quantity.

Then, use the location and quantity from the metafield(input query) to check the inventory of the warehouse is zero or not and route the order to the warehouse when it has zero inventory.

We actually have metafields for this already and are already routing to the warehouse with zero inventory as noted above, and it’s not working. I thought you said that there might be a limitation around routing to warehouses without inventory.

@Liam-Shopify hey do you happen to know anyone from this team who can chime in?

1 Like

Have you tried the following output to fulfill to the same location?

{
  "operations": [
    {
      "rank": {
        "fulfillmentGroupHandle": "1",
        "rankings": [
          {
            "locationHandle": "67514040438",
            "rank": 0
          }
        ]
      }
    },
    {
      "rank": {
        "fulfillmentGroupHandle": "2",
        "rankings": [
          {
            "locationHandle": "67514040438",
            "rank": 0
          }
        ]
      }
    }
  ]
}

Yes, we’ve tried this. It does not work. It appears that other functionality is overwriting our location-rule function when native inventory = 0.