创建具有图像使用shopify_api红宝石创业板新产品(Creating a new produc

2019-09-24 00:39发布

Shopify有一个RESTful API和我已经使用了更新库存水平得心应手红宝石shopify_api宝石。

今天我要做新的东西,以创建图像的新产品,我想使用的,而不是使用像其他的客户端或httparty与API互动shopify_api宝石。

该Shopify API支持simultanious创建默认有与将由Shopify使用此调用下载的产品图片新产品:

POST /admin/products.json

随着一个JSON请求字符串:

{
  "product": {
    "title": "Burton Custom Freestlye 151",
    "body_html": "<strong>Good snowboard!</strong>",
    "vendor": "Burton",
    "product_type": "Snowboard",
    "images": [
      {
        "src": "http://example.com/rails_logo.gif"
      }
    ]
  }
}

现在的问题是我怎么做这个使用shopify_api宝石?

干杯,

马库斯

Answer 1:

我发现了一个不雅的方式来做到这一点。 请参阅下面的解决方案:

images = []
image = {}
image["src"] = "http://i.dailymail.co.uk/i/pix/2012/09/10/article-0-14EE3D4E000005DC-303_634x434.jpg"

images << image

variant = ShopifyAPI::Variant.new(
  :price                => 69.99,
  :inventory_management => 'shopify',
  :inventory_quantity   => 69, 
  :sku => "MS_TEST"
)

product = ShopifyAPI::Product.new(
:title => "MS Test",
:body_html =>  "<strong>Good snowboard!</strong>",
:vendor => "MS Test",
:product_type => "MS Test",
:images => images,
:variants => variant
)


文章来源: Creating a new product with image using the shopify_api Ruby gem
标签: ruby shopify