The integration between Shopify and Google Sheets via Zapier is not capturing every purchased item when processing new paid orders. Only the first product is extracted even when multiple items are present, leaving crucial product details unrecorded. I attempted to use a Python script to parse customer details such as address, email, and phone number along with product information, but the script fails to iterate through all the items. Consider the revised code snippet below that adopts different variable names and structure to better manage multiple product entries:
def merge_parts(data_string):
combined = []
segments = data_string.split('|')
for index in range(0, len(segments), 2):
if index + 1 < len(segments):
combined.append(f"{segments[index]}-{segments[index+1]}")
return combined
def retrieve_safe(item_list, pos):
return item_list[pos] if 0 <= pos < len(item_list) else 'undefined'
input_data = {
'quantities': '3;2',
'items': 'Alpha;Beta',
'timestamps': '2022-05-01|09:30|2022-05-01|09:35',
'contact': '5551234567',
'note': 'Deliver ASAP',
'address': '456 Central Ave',
'status': 'confirmed',
'last_name': 'Smith',
'first_name': 'Alice',
'email': '[email protected]'
}
output_results = []
quant_arr = input_data.get('quantities', '').split(';')
item_arr = input_data.get('items', '').split(';')
time_arr = merge_parts(input_data.get('timestamps', ''))
for idx, item in enumerate(item_arr):
output_results.append({
'quantity': retrieve_safe(quant_arr, idx),
'item': item,
'phone': input_data.get('contact'),
'note': input_data.get('note', ''),
'address': input_data.get('address'),
'status': input_data.get('status'),
'last_name': input_data.get('last_name'),
'first_name': input_data.get('first_name'),
'email': input_data.get('email'),
'time': retrieve_safe(time_arr, idx)
})
return output_results