【发布时间】:2019-10-01 19:42:39
【问题描述】:
我正在尝试使用WooCommerce 中的variations 创建产品,但我收到此错误:
{u'message': u'No route was found matching the URL and request method', u'code': u'rest_no_route', u'data': {u'status': 404}}
当我从 API 运行 create_variation 函数时。
我对我创建的产品的属性运行了GET,但它没有发现任何属性,即使我创建产品时的打印响应列出了属性。
这是我创建变量产品的代码:
data = {
"name": row[3],
"type": "variable",
"description": row[4],
"images": [
{
"src": row[15],
"position": 0
}
],
"in_stock": True,
"sku": row[2],
'attributes': [
{
'name': 'Size',
'variation': True,
'visible': True,
'options': sizeList,
},
{
'name': 'Color',
'variation': True,
'visible': True,
'options': colorList,
}
],
}
print(wcapiNew.post("products", data).json())
这是我创建变体的代码:
result = wcapi.get("products/sku/"+row[2]).json()
product_id = result['product']['id']
variationData = {
"regular_price": row[17],
"image": {
"src": row[13]
},
"sku": row[19],
"attributes": [
{
"name": "Color",
"option": row[6]
},
{
"name": "Size",
"option": row[10]
}
]
}
print(wcapiNew.post("products/"+str(product_id)+"/variations", variationData).json())
我一直在努力弄清楚自己做错了什么,但我现在一无所知。
感谢任何帮助。谢谢。
【问题讨论】:
-
任何提示如何解决这个问题?
-
仍然没有得到它的工作。最后用 php 重新制作它,它工作得非常好。
标签: wordpress woocommerce