Problem Summary
I’m using Zapier to extract data from Shopify orders and send it to Google Sheets. Products within subscription bundles are showing quantity 0, when I run tests it counts fine. But, when I get live orders, all the product counts besides the bundle are marked 0.
Setup
- **Platform: Shopify + AWTOMIC for bundled subscription meal plans
- Site: https://cravemealprepco.com
- Google Sheet: Template link of live order, followed by test
- Zap Structure:
a) 1 – Shopify – New Paid Order
b) 2 – Filter by Zapier → Only continues if line items bundle name includes “Regular”
c) 3 – Code by Zapier → Process meal data (code below)
d) 4 – Google Sheets → Create Spreadsheet Row
/*
UPDATED VERSION - Handles both bundle items and individual items
*/
//////////////////// 1. master list - Updated with actual Shopify names ////////////////////
const meals = {
// Add the actual product names from Shopify
"Peanut Butter Power Balls": 0,
"Regular Protein - Meal Plan": 0,
"Overnight Oats": 0,
"Protein Donuts ( 2 pack )": 0,
// Keep your existing names in case they're used elsewhere
"Chocolate Strawberry Protein Pancakes": 0,
"Crave Breakfast Sandwich (Gluten Free)": 0,
"BBQ Chicken Mac N' Cheese": 0,
"French Onion Chicken - (Gluten Free)": 0,
"Chipotle Chicken (Gluten Free)": 0,
"Crave Fil A (Gluten Free)": 0,
"Turkey Bolognese": 0,
"Fiesta Turkey Bowl (Gluten Free)": 0,
"Sweet Chili Turkey Bowl (Gluten Free)": 0,
"Adobo Braised Beef Bowl - (Gluten Free)": 0,
"Beef Empanada": 0,
"Sesame Ginger Beef": 0,
"Big Mac Bowl (Gluten free)": 0,
"Asian Crunch Salad": 0,
"Strawberry Walnut Chicken Salad (GF)": 0,
"Mediterranean Chicken Hummus Wrap": 0,
"Grilled Chicken Chimichurri Bowl (GF) (DF) (SF)": 0,
"Grilled Chicken Caesar Wrap": 0,
"Beef & Broccoli (GF) (DF) (SF)": 0,
"Steak & Eggs (GF) (DF) (SF)": 0,
"Pulled Chicken (GF) (DF) (SF)": 0,
"Turkey Burger (GF) (DF) (SF)": 0,
"Grilled Chicken (GF) (DF) (SF)": 0,
"Chili Lime Turkey (GF) (DF) (SF)": 0
};
//////////////////// 2. normalise inputs ////////////////////
const names = Array.isArray(inputData.meal_name)
? inputData.meal_name
: (inputData.meal_name || "").split(/s*,s*/).filter(Boolean);
const qtys = Array.isArray(inputData.meal_qty)
? inputData.meal_qty
: (inputData.meal_qty || "").split(/s*,s*/).filter(Boolean);
//////////////////// 3. Handle bundle data from inputData object ////////////////////
// Check if there are bundle items directly in inputData
const bundleItems = [];
for (const key in inputData) {
// Look for meal names that end with "- Regular" or "- Double"
if (key.match(/s*-s*(regular|double)$/i) && typeof inputData[key] === 'string' && !isNaN(inputData[key])) {
const qty = parseInt(inputData[key], 10);
if (qty > 0) {
bundleItems.push({
name: key,
qty: qty
});
}
}
}
//////////////////// 4. build the counts ////////////////////
const unknown = [];
// Process regular meal_name/meal_qty arrays
for (let i = 0; i < names.length; i++) {
let title = (names[i] || "").trim();
// strip "- Regular" or "- Double" (any case, any spaces)
title = title.replace(/s*-s*(regular|double)$/i, "").trim();
const qty = parseInt(qtys[i] || "0", 10);
if (meals.hasOwnProperty(title)) {
meals[title] += qty;
} else {
unknown.push(title);
}
}
// Process bundle items found in inputData
for (const item of bundleItems) {
let title = item.name.trim();
// strip "- Regular" or "- Double" (any case, any spaces)
title = title.replace(/s*-s*(regular|double)$/i, "").trim();
if (meals.hasOwnProperty(title)) {
meals[title] += item.qty;
} else {
unknown.push(title);
}
}
//////////////////// 5. return the row ////////////////////
return {
name: inputData.billing_name || "",
phone: inputData.billing_phone || "",
email: inputData.email || "",
unknown_titles: unknown,
...meals
};
Input Data Structure
The Code by Zapeir step receies:
- billing_name: Billing Address Name
- billing_phone: Customer Phone
- email: Email
- meal_qty: Line Items Quantity
- meal_name: Line Items Title
Expected Vs Actual Behavior
Expected: When a new order is placed the product quantities should be updated correctly in to the spreadsheet row.
Actual: When a new order is placed the product quantities all show as ‘0’ besides the bundle item. When I run same order as a test it works fine.
Question
How can I make it so that I receive same results (Track the quantity for each meal for new orders and add them to the sheet correctly). I was thinking the issue might be with the JavaScript code.
