【发布时间】:2017-03-20 22:10:58
【问题描述】:
我似乎无法创建具有多个选项的产品。我已经尝试了所有方法,Shopify 官方库中的文档很差。我查看了整个 API 参考指南并搜索了其他形式,但似乎找不到正确的语法。代码如下。我正在尝试创建具有两个选项的产品,例如 option1 是大小,option2 是颜色。打印输出也没有显示错误消息,但 Shopify 商店中不显示变体选项,仅显示具有 0 个变体的产品。
new_product = shopify.Product()
new_product.title = "My Product"
new_product.handle = "test-product"
##what I've tried... and countless others
#First example of new_product.variants
new_product.variants = shopify.Variant({'options': {'option1' : ['S', 'M', 'L', 'XL'], 'option2' : ['Black', 'Blue', 'Green', 'Red']}, 'product_id': '123456789'})
#Second example of new_product.variants
new_product.variants = shopify.Variant({'options': [{'option1': 'Size', 'option2': 'Colour','option3': 'Material'}]})
#Thrid example of new_product.variants
new_product.variants = shopify.Variant([
{'title':'v1', 'option1': 'Red', 'option2': 'M'},
{'title':'v2', 'option1' :'Blue', 'option2' :'L'}
])
new_product.save()
##No errors are output, but doesn't create variants with options
if new_product.errors:
print new_product.errors.full_messages()
print "Done"
【问题讨论】: