使用shopifyapipython,添加新产品并注明价格和“需要运费”:Fals

2024-05-14 21:04:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过pythonshopifyapi添加一个新产品。我知道如何添加标题,正文和图片,但我有问题增加价格,我需要有'需要'运输':错误。我找不到任何地方可以做到这一点。在

这就是我目前所拥有的。在

import shopify    
API_KEY = 'dsfsdsdsdsdsad'
PASSWORD = 'sadsdasdasdas'

shop_url = "https://%s:%s@teststore.myshopify.com/admin" % (API_KEY, PASSWORD)
shopify.ShopifyResource.set_site(shop_url)



path = "audi.jpg"

new_product = shopify.Product()
new_product.title = "Audi pictures test "
new_product.body_html = "body of the page <br/><br/> test <br/> test"

###########this part is so far good. but the bottom part is not working#### 

variant = shopify.Variant(price=9.99)) # this does not work
new_product.variant() # this does not work
variant_2 = shopify.Variant(requires_shipping=False) #this does not work
new_product.variant_2() This does not work 



image = shopify.Image()

with open(path, "rb") as f:
    filename = path.split("/")[-1:][0]
    encoded = f.read()
    image.attach_image(encoded, filename=filename)

new_product.images = [image] # Here's the change
new_product.save()

Tags: thepathtestimagebrapinewnot
1条回答
网友
1楼 · 发布于 2024-05-14 21:04:56

只有前缀选项(例如,product_id表示变量,order_id表示实现)应作为显式参数传递给构造函数。如果要初始化资源的属性,则需要将它们作为dict传递

你也没有把你的新变种和你的新产品联系在一起。在

这将有助于:

new_product = shopify.Product()
new_product.title = "Shopify Logo T-Shirt"
new_product.body_html = "<b>Test description</b>"
variant = shopify.Variant({'price': 9.99, 'requires_shipping': False})
new_product.variants = [variant]
new_product.save()
=> True

您还可以在初始化后指定资源的属性,就像您已经为产品资源所做的那样。在

^{pr2}$

另一个选择是先保存产品并通过显式传递product_id初始化变量,例如

shopify.Variant(product_id=1234567)

查看README以获取更多用法示例。在

相关问题 更多 >

    热门问题