【问题标题】:Using Shopify API Python, add new product with price and 'requires_shipping': False使用 Shopify API Python,添加带有价格和“requires_shipping”的新产品:False
【发布时间】:2018-02-01 16:37:40
【问题描述】:

我正在尝试通过 Python Shopify API 添加新产品。我知道如何添加标题和正文以及图片,但我在添加价格时遇到问题,我需要'requires_shipping':False。我在任何地方都找不到如何实现这一点。

这是我目前所拥有的。

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

【问题讨论】:

    标签: python api shopify variants


    【解决方案1】:

    只有前缀选项(例如,product_id 用于 Variants,order_id 用于 Fulfillments)应作为显式参数传递给构造函数。如果要初始化资源的属性,则需要将它们作为 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
    

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

    variant = shopify.Variant()
    variant.price = 9.99
    variant.requires_shipping = False
    

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

    shopify.Variant(product_id=1234567)

    查看README 了解更多用法示例。

    【讨论】:

    • 您知道如何添加多张图片吗?我只能使用我拥有的代码添加 1 张图片。但是,我很难添加 1 张以上的图片。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    相关资源
    最近更新 更多