Shopify Python API:如何将产品添加到集合中?

时间:2023-01-19 16:49:27

I am using the Shopify Python API in an django app to interact with my Shopify Store.

我在django应用程序中使用Shopify Python API与我的Shopify商店进行交互。

I have a collection - called - best sellers.

我有一个系列 - 叫做畅销书。

I am looking to create a batch update to this collection - that is add/remove products to this collection. However, they python API docs does not seem to say much about how to do so. How do I fetch a collection by name? How do I add a product to it?

我希望为此集合创建批量更新 - 即向此集合添加/删除产品。但是,他们的python API文档似乎并没有多说这么做。如何按名称获取集合?如何添加产品?

Thank you for your help.

感谢您的帮助。


This is what I found

这就是我发现的

x=shopify.CustomCollection.find(handle="best-sellers")

y=shopify.Collect() #creates a new collect

y = shopify.Collect()#create一个新的收集

p = shopify.Product.find(118751076) # gets me the product

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

So the questions is how do I add the product "p" above to the Custom Collection "x" ?

所以问题是如何将上面的产品“p”添加到Custom Collection“x”?

2 个解决方案

#1


2  

Create a collect to add a product to a custom collection.

创建集合以将产品添加到自定义集合。

Shopify API – Collect Documentation

Shopify API - 收集文档

This can be done using the Shopify Python API as follows

这可以使用Shopify Python API完成,如下所示

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

#2


-1  

Fetches all products that belong to a certain collection

获取属于特定集合的所有产品

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

Create a new product with multiple product variants

创建具有多个产品变体的新产品

>>> 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

via - http://wiki.shopify.com/Using_the_shopify_python_api#Receive_a_list_of_all_Products

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

#1


2  

Create a collect to add a product to a custom collection.

创建集合以将产品添加到自定义集合。

Shopify API – Collect Documentation

Shopify API - 收集文档

This can be done using the Shopify Python API as follows

这可以使用Shopify Python API完成,如下所示

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

#2


-1  

Fetches all products that belong to a certain collection

获取属于特定集合的所有产品

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

Create a new product with multiple product variants

创建具有多个产品变体的新产品

>>> 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

via - http://wiki.shopify.com/Using_the_shopify_python_api#Receive_a_list_of_all_Products

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