Skip to content

Solving Shopify Bundle Quantity Logic with Zapier Code

In high-volume e-commerce, bundled subscription products present a unique data challenge. When a customer buys a “Family Pack” subscription (1 bundle containing 4 units of Product A), Shopify’s API often passes the quantity as “1” for the parent SKU.

Standard Zapier “Line Item” formatters often fail to “look inside” the bundle properties to calculate the true inventory impact. This guide solves the specific issue of Zapier Code by Zapier failing to count sub-quantities in Shopify subscription orders.

The “Aha!” Solution: Flattening and Multiplication Logic

Section titled “The “Aha!” Solution: Flattening and Multiplication Logic”

The limitation isn’t in Zapier’s infrastructure, but in how it parses nested JSON arrays. The standard “Find Order” or “New Order” trigger provides a surface-level view of line items.

The “Aha!” moment comes from treating the Shopify line_items array as a raw object inside a Code by Zapier block. Instead of relying on Zapier’s built-in mapping, we use JavaScript to iterate through the properties or component_id fields, multiply the bundle quantity by the component quantity, and return a flattened array that downstream apps (like ShipStation, NetSuite, or Google Sheets) can read as individual line items.

Ensure your trigger captures the full payload.

  • Trigger: Shopify
  • Event: New Order (or New Paid Order)
  • Note: If using a subscription app like Recharge, use the “New Subscription Order” trigger.

2. The Code Block: Calculating Sub-Quantities

Section titled “2. The Code Block: Calculating Sub-Quantities”

Add a Code by Zapier step using JavaScript. You must map the “Line Items” from Shopify into the “Input Data” field.

Input Data Mapping:

Key Value (from Shopify Trigger)
rawLineItems Line Items (The entire array)

The Code Script:

// Parse the input data
const lineItems = JSON.parse(inputData.rawLineItems);
let processedItems = [];
lineItems.forEach(item => {
// Check if item has bundle properties (common in Shopify bundles/subscriptions)
// We look for a property that defines the 'Items per Bundle'
let bundleMultiplier = 1;
if (item.properties) {
const bundleProp = item.properties.find(p => p.name === 'bundle_units' || p.name === '_bundle_qty');
if (bundleProp) {
bundleMultiplier = parseInt(bundleProp.value);
}
}
// Calculate the true quantity: Order Qty * Internal Bundle Qty
const totalActualQuantity = item.quantity * bundleMultiplier;
processedItems.push({
sku: item.sku,
name: item.name,
original_qty: item.quantity,
bundle_multiplier: bundleMultiplier,
final_quantity: totalActualQuantity,
price: item.price
});
});
return { processedItems };

To ensure your downstream steps work correctly, the Code block will output an array of objects. Here is the structure the next step will receive:

{
"processedItems": [
{
"sku": "SAMP-PROD-01",
"name": "Subscription Bundle A",
"original_qty": 2,
"bundle_multiplier": 4,
"final_quantity": 8,
"price": "45.00"
}
]
}

4. The Action: Mapping to the Final Destination

Section titled “4. The Action: Mapping to the Final Destination”

In your final action step (e.g., Google Sheets > Create Spreadsheet Row or ShipStation > Create Order), you will now have access to the final_quantity field.

  • Navigate to the Action tab.
  • In the Quantity field, select the final_quantity output from the Code by Zapier step.
  • Zapier will automatically loop through the processedItems array if the destination app supports line items.
Edge Case Solution
Non-Bundled Items The script includes a default bundleMultiplier = 1. This ensures standard products are processed with their original quantity.
Missing SKUs Some bundle apps don’t assign SKUs to sub-components. Ensure your script checks if (!item.sku) and assigns a fallback string to prevent errors in ERP syncs.
Recharge Integration If using Recharge, bundles are often handled via “Onetime” vs “Subscription” line item types. You may need to add a conditional if (item.type === 'subscription') to your logic.
Zapier Loop Limits If an order contains more than 25 unique line items, standard Zapier steps might throttle. The Code block handles this efficiently, but the following step may require Looping by Zapier if the destination app doesn’t support native arrays.

By bypassing Zapier’s default line-item mapping and using a calculated logic block, you eliminate the “Missing Quantity” bug common in Shopify bundle apps. This ensures your inventory levels remain accurate and your fulfillment team receives the correct item counts for every subscription cycle.