簡體   English   中英

使用 shopify_api Ruby gem 創建帶有圖像的新產品

[英]Creating a new product with image using the shopify_api Ruby gem

Shopify 有一個 RESTful API 和一個方便的 shopify_api ruby​​ gem,我已經用它來更新庫存水平。

今天我必須做一些新的事情,創建一個帶有圖像的新產品,我想使用 shopify_api gem 而不是使用 rest-client 或 httparty 之類的東西來與 API 交互。

Shopify API 支持同時創建具有默認變體的新產品和 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 gem 執行此操作?

干杯,

馬庫斯

我找到了一種不優雅的方法來做到這一點。 請參閱下面的解決方案:

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
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM