2013-02-13 150 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