2013-02-13 144 views
1

我在一个django应用程序中使用Shopify Python API与我的Shopify商店进行交互。Shopify Python API:如何将产品添加到集合?

我有一个集合 - 称为 - 畅销书。

我期待为此集合创建批量更新 - 即向此集合中添加/删除产品。不过,他们的python API文档似乎没有多说如何这样做。如何按名称获取集合?如何添加产品?

谢谢你的帮助。


这是我发现

X = shopify.CustomCollection.find(手柄= “畅销书”)

Y = shopify.Collect()#创建一个新的收集

p = shopify.Product.find(118751076)#把我的产品

所以问题是如何添加产品“P”上面的自定义集合“X”?

回答

2

创建一个收集到产品添加到一个自定义集合。

Shopify API – Collect Documentation

这可以通过使用Shopify的Python API在如下

collect = shopify.Collect({ 'product_id': product_id, 'collection_id': collection_id }) 
collect.save() 
+1

此外,我也想到了这一点 - 这与您发布的内容相同:>>> z = shopify.Collect() >>> z.product_id = p.id >>> z.collection_id = x [0 ] .id >>> z.save() – 2013-02-13 04:16:38

0

获取属于某个集合

>>> shopify.Product.find(collection_id=841564295) 
[product(632910392)] 

所有产品创建多个产品新产品变型

>>> new_product = shopify.Product() 
>>> print new_product.id # Only exists in memory for now 
None 
>>> new_product.product_type = "Snowboard" 
>>> new_product.body_html = "<strong>Good snowboard!</strong>" 
>>> new_product.title = "Burton Custom Freestlye 151" 
>>> variant1 = shopify.Variant() 
>>> variant2 = shopify.Variant(dict(price="20.00", option1="Second")) # attributes can  be set at creation 
>>> new_product.variants = [variant1, variant2] 
>>> new_product.vendor = "Burton" 
>>> new_product.save() # Sends request to Shopify 
True 
>>> new_product.id 
1048875193 

通过 - http://wiki.shopify.com/Using_the_shopify_python_api#Receive_a_list_of_all_Products

+0

当上述是映射的产品到集合中的代码来完成? – 2013-02-13 03:50:52