Solving Shopify Local Delivery: Prioritizing Your Closest Store with Custom Flow Logic
Hey everyone, let's dive into a common challenge that many of you running multi-location Shopify stores might face, especially when it comes to local deliveries. I recently followed a really insightful discussion in the Shopify community that highlighted a specific pain point: how Shopify handles local delivery orders when you have a prioritized warehouse location.
Sebastian_Young, a store owner, kicked off the thread with a classic problem: his Shopify store has two locations, a 'Warehouse' and a 'Store'. The Warehouse is set as the priority for shipping orders, which makes perfect sense. However, for local delivery, Shopify was also prioritizing the Warehouse, even when the 'Store' was much closer to the customer and had all the necessary inventory. This meant local deliveries were getting assigned to a distant location, creating inefficiencies and potential delays. Sound familiar?
The Core Problem: Default Routing Rules Don't Always Distinguish
The crux of Sebastian's issue, and what many of us run into, is that Shopify's default order routing rules in 'Shipping and delivery' settings often apply broadly. As Sebastian pointed out, any routing rules he set to prioritize the 'closest location' would then affect both shipping and local delivery orders. He needed the Warehouse prioritized for shipping but the closest Store for local delivery. It's a nuanced distinction that the standard settings don't easily accommodate.
Tim_1, a helpful community expert, jumped in with some initial thoughts. He suggested turning off local delivery for the Warehouse or limiting its delivery radius. While good ideas in some scenarios, Sebastian explained why these wouldn't work for him: he needed the Warehouse to cover a wider delivery reach and also to serve as a backup for inventory his Store might not have. Synchronizing inventory across separate local delivery locations also proved to be a complex hurdle.
There's also a promising new Shopify Function for order routing in beta, but for now, it's a Plus-only feature. So, for most of us, we need a different approach.
The Shopify Flow Breakthrough: Intelligent Order Routing
This is where Shopify Flow comes into play. The conversation quickly shifted to building a custom Flow to handle this specific local delivery scenario. Sebastian had tried something similar before but ran into a challenge: how to reliably check if a specific location (like the Warehouse) actually had enough inventory for all line items before moving a fulfillment order. It's not enough for a location to merely 'stock' an item; it needs to have 'available' inventory.
Initially, Tim suggested trying to just move the fulfillment order without a prior check, as the API is designed to fail if the destination doesn't stock the item. However, Sebastian clarified a crucial detail: "A Location stocking an item refers to it carrying the item rather than it having inventory." This means the API might not fail if the location *carries* the item but just doesn't *currently have stock* for that particular order. This was a lightbulb moment for the discussion!
The solution needed to be more robust: a Flow that would not only identify local delivery orders but also meticulously check inventory levels at the desired location for each individual line item.
Building the Winning Flow Logic (Step-by-Step)
After some back and forth, Tim and Sebastian hammered out a Flow structure that ultimately worked perfectly. Here’s a breakdown of how you can set up a similar Shopify Flow to ensure your local delivery orders are routed to the Warehouse only if it has all the necessary inventory, otherwise allowing them to remain at the closest Store (or default location).
Step 1: Set Your Flow Trigger and Initial Conditions
Start with a trigger that fires when an order is created or a fulfillment order is created. Then, apply conditions to filter for local delivery orders and ensure they haven't already been assigned to your Warehouse.
- Trigger:
Order created(orFulfillment order createdif you prefer). - Condition 1 (Optional but Recommended):
Order type is Local Delivery. - Condition 2 (Optional but Recommended):
Order is NOT assigned to Warehouse(or whatever your primary, non-local delivery location is). This prevents unnecessary processing.
Step 2: Loop Through Line Items and Check Inventory
This is the critical part. You need to examine each item in the order to confirm inventory at your Warehouse.
- Action: Add a
For eachloop and selectfulfillmentOrder.lineItems. - Inside the loop, add a Condition: This condition checks if any line item's required quantity exceeds the available inventory at your 'Warehouse' location. Here’s the logic you'll need:
For this lineItem it fetches a list of lineItem.variant.inventoryItem.inventoryLevels
and then
there is at least one inventoryLevel which
has location.name "Warehouse" and at the same time this inventoryItem.available is less then what we need to fulfil.
Essentially, you're looking for a scenario where the Warehouse *doesn't* have enough stock for a particular item. The condition would look something like this:
- If the condition is TRUE (Warehouse doesn't have enough stock): Add an action to
Fail the Flow. This stops the process, leaving the order at its initially assigned (likely closest) location.
Step 3: Move Fulfillment Order (If All Checks Pass)
If the For each loop completes without failing (meaning the Warehouse has sufficient inventory for *all* line items), then you can confidently move the fulfillment order.
- Action: After the loop, add a
Move Fulfillment Orderaction. - Configuration: Set the destination to your 'Warehouse' location.
Sebastian initially confirmed that he misunderstood the Flow run details, but after some testing, he reported back that this exact setup was "working perfectly." This is a fantastic example of how a custom Shopify Flow can bridge the gap where default settings fall short, giving you precise control over your fulfillment logic.
This community discussion really highlighted the power of diving into the specifics of Shopify Flow and understanding exactly what each data point (like 'stocking' vs. 'available inventory') truly means. It's a testament to how collaborative problem-solving within the community can lead to robust, practical solutions for real-world store operations. Implementing a Flow like this can significantly streamline your local delivery process, ensuring orders are fulfilled from the most logical and efficient location based on actual inventory, not just a blanket prioritization.
