【问题标题】:Zapier Action Code: Python input_data[] stripping nulls from listZapier 动作代码:Python input_data[] 从列表中剥离空值
【发布时间】:2020-04-09 11:03:42
【问题描述】:

我一直在尝试使用 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,但如果可以的话,我很高兴看到它。

【问题讨论】:

  • 我也有这个问题。我有一个包含关键字 X 的键的输入,我想要它的值。我事先不知道确切的键,但我希望能够遍历所有键,找到哪个键包含关键字 X,并访问相关值。现在,我不能可靠地做到这一点,因为空值会被丢弃。

标签: python magento zapier


【解决方案1】:

根据 Zapier 开发人员 2019 年 3 月的answer,将输入强制转换为字符串的方式已修复,并且没有解决此问题的计划。

一个suggested workaround是:

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

不过,这确实使使用 Zapier 的目的失败了一半。

【讨论】:

  • This answer 解释了如何使用 Zapier 设置网络挂钩,并声称您将希望使用 Python 来访问 JSON。
  • 这是another question 要求不要丢弃空值,这引起了 Zapier 开发人员的一些关注,但似乎没有得到任何地方。
猜你喜欢
  • 2019-05-12
  • 2019-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-07
相关资源
最近更新 更多