Zapier 操作代码:Python input_data[] 从列表中剥离空值

2024-02-15

我一直在尝试使用 Python 为 Zapier 创建自定义代码。

该代码从 Magento 2 发票中提取两个列表。它们是行项目的详细信息,我们使用这些数据来更新库存系统上的库存。不幸的是,捆绑产品显示了子产品,我需要将子产品的数量清零,这样它们就不会从库存中删除。

如果父项是“捆绑包”,我已将逻辑全部排序以将库存商品数量设置为零。

问题在于提取输入数据。空值正在被丢弃。

例如,如果列表为 null、null、null、bundle,则结果只是bundle 如果列表是 1,1,1,null 我最终得到的是 1,1,1

有没有办法从输入数据字段中提取数据而不删除空值?

代码目前看起来像这样。

# if the product is a child of a bundle then zero out the quantity or it will take extra stock

quantity = str(input_data["item_qty_invoiced"])
quantity_array = quantity.split(",")

cleaned_quantity_list = ""

product_type = str(input_data["item_product_type"])
product_type_array = product_type.split(",")

num_of_line_items = len(product_type_array)
index = 0

while index < num_of_line_items:

    if product_type_array[index] == "bundle":
        quantity_array[index] = 0

    index += 1

cleaned_quantity_list = ",".join(str(i) for i in quantity_array)    

return {'item_qty_invoiced': cleaned_quantity_list}

我还没有尝试过 javascript,但我很高兴看看它是否是一个选项。


根据 2019 年 3 月answer https://stackoverflow.com/a/55244199/1292652Zapier 开发人员修复了将输入强制转换为字符串的方式,并且没有计划解决此问题。

One 建议的解决方法 https://stackoverflow.com/questions/55233255/in-zapier-how-do-i-get-the-inputs-to-my-python-run-code-action-to-be-passed-i#comment97221780_55244199 was:

最好的办法是制作一个 CLI 应用程序来复制 twitter 操作。然后你可以将输出设置为json字符串,我们不会碰它。我已经在几个地方做到了这一点,而且效果很好(除了我们应该为您处理时必须自己与 Twitter 交互的额外负担之外)

但这确实违背了使用 Zapier 的一半目的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Zapier 操作代码:Python input_data[] 从列表中剥离空值 的相关文章