2012-02-09 35 views
4

Shopifyを使用して私のショップを管理すると考えています。私はAPIを使ってウェブサイトに製品を追加する必要があります。Shopify API - バスケットに追加

http://api.shopify.com/

私は、このAPIコールで商品や株式を取得することができます:

http://api.shopify.com/product.html#index

しかし、その後、私は「バスケットに追加」したい - 私は、APIドキュメントから見ることができませんこれを行う方法。 は一度バスケットに追加 - 私は何かなどを表示できるようにバスケットの内容を取得したいのですが...

"2 items : £130 - checkout" 

を私は詳細な回答を必要としない - ちょうど正しい方向に私を指す - のおかげで。

答えて

8

Shopifyバックエンドは、個々のユーザーカートについては何も知らず、ブラウザの土地にのみ存在します。私の間違いは、バックエンドはカートについて知っていますが、REST APIで編集することはできません。 Here's the Cart endpoint if you're interested in getting carts

ユーザーのカートを操作するには、店頭からAjax APIを使用する必要があります。具体的には、this callは、カートに製品を追加します:

次のようになりますJSONを返す
http://store.myshopify.com/cart.add.js?quantity=2&id=30104012 

{ 
    "handle": "amelia", 
    "line_price": 4000, 
    "requires_shipping": true, 
    "price": 2000, 
    "title": "amelia - medium", 
    "url": "/products/amelia", 
    "quantity": 2, 
    "id": 30104012, 
    "grams": 200, 
    "sku": "", 
    "vendor": "the candi factory", 
    "image": "http://static.shopify.com/s/files/1/0040/7092/products/2766315_da1b.png?1268045506", 
    "variant_id": 30104012 
} 

あなたはfollowing callを使用して、カート自体を取得できます。

http://store.myshopify.com/cart.js 

あなたにこれを手に入れる:

{ 
    "items": [ 
     { 
      "handle": "aquarius", 
      "line_price": 6000, 
      "requires_shipping": true, 
      "price": 2000, 
      "title": "aquarius - medium", 
      "url": "/products/aquarius", 
      "quantity": 3, 
      "id": 30104042, 
      "grams": 181, 
      "sku": "", 
      "vendor": "the candi factory", 
      "image": "http://static.shopify.com/s/files/1/0040/7092/products/aquarius_1.gif?1268045506", 
      "variant_id": 30104042 
     }, 
     { 
      "handle": "amelia", 
      "line_price": 4000, 
      "requires_shipping": true, 
      "price": 2000, 
      "title": "amelia - medium", 
      "url": "/products/amelia", 
      "quantity": 2, 
      "id": 30104012, 
      "grams": 200, 
      "sku": "", 
      "vendor": "the candi factory", 
      "image": "http://static.shopify.com/s/files/1/0040/7092/products/2766315_da1b.png?1268045506", 
      "variant_id": 30104012 
     } 
    ], 
    "requires_shipping": true, 
    "total_price": 10000, 
    "attributes": null, 
    "item_count": 5, 
    "note": null, 
    "total_weight": 947 
} 
+0

Davidに感謝します。完璧。 – Boz

+1

こんにちは、API経由でカートにカスタムを追加することは可能でしょうか?私はカスタム名、カスタム説明、カスタム価格をIDなしでカートに入れたいのですか?ありがとうございます。 –

関連する問題