[英]Using Shopify API Python, add new product with price and 'requires_shipping': False
I am trying to add a new product through the Python Shopify API. 我正在尝试通过Python Shopify API添加新产品。 I know how to add title and body and a picture but I am having issues with adding price and I need to have 'requires_shipping': False.
我知道如何添加标题,正文和图片,但是我在添加价格时遇到了问题,我需要使用“ requires_shipping”:错误。 I can't find anywhere how to achieve this.
我在任何地方都找不到如何实现这一目标的。
This is what I have so far. 到目前为止,这就是我所拥有的。
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()
Only prefix options (eg product_id
for Variants, order_id
for Fulfillments) should be passed as explicit parameters to the constructor. 仅前缀选项(例如,对于
order_id
为product_id
,对于实现为order_id
)应作为显式参数传递给构造函数。 If you want to initialize the attributes of the resource you'll need to pass them in as a dict. 如果要初始化资源的属性,则需要将它们作为字典传递。
You're also not associating your new variant with your new product at any point. 您也不会在任何时候将新版本与新产品相关联。
This should help: 这应该有助于:
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
You can also specify the attributes of the resource after initializing, as you're already doing for the Product resource. 您也可以在初始化后指定资源的属性,就像您对Product资源所做的那样。
variant = shopify.Variant()
variant.price = 9.99
variant.requires_shipping = False
Another option would be to save the product first and initialize the variant by passing the product_id
explicitly, eg 另一个选择是先保存产品,然后通过显式传递
product_id
初始化变体,例如
shopify.Variant(product_id=1234567)
Take a look at the README for more usage examples. 查看自述文件以获取更多用法示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.