2014-10-03 35 views
2

我一直在對此反應過度,所以希望有人能提供幫助。 Ruby/HTTParty/BigCommerce Gem(它的工作原理)。如何通過BigCommerce API將SKU附加到產品; 「product_option_id」字段無效

錯誤是:字段'product_option_id'無效;試圖經由

myresponse = HTTParty.post("#{@store_url}products/800/skus", 
     :body=>{ 
      :sku => "111204", 
      :options => [ 
      { 
       :product_option_id => 16, 
       :option_value_id => 46 
      } 
      ] 
      }.to_json, 
      :headers => {'Content-Type' => 'application/json' }, 
     :basic_auth => @auth) 

添加一個SKU時基本上看不到/找出其中「product_option_id」被參照;您不能通過我可以看到的API將選項直接鏈接到產品。

關於這個問題還有兩個其他問題,但對我來說都沒有有用的答案。

在此之前,我已經;

  • 創建了一個產品; id是800,sku是111240P。響應\產品?SKU = 111240P是

{ 「ID」=> 「800」, 「keyword_filter」=> 「NULL」, 「名」=> 「不透明大腿高」, 「輸入」=> 「物理」,「SKU」=>「111204P」,「描述」=>「不透明尼龍大腿高」,「search_keywords」=>無,「availability_description」=>零,「price」=>「3.8200」 cost_price「=>」2.1800「,」retail_price「=>」0.0000「,」sale_price「=>」0.0000「,」calculated_price「=>」3.8200「,」sort_order「=>」0「,」is_visible「=> true「,」is_featured「=>」false「,」related_products「=>」NULL「,」inventory_level「=>」0「,」inventory_warning_level「=>」0「,」warranty「=>」NULL「 「=>」0.1000「,」width「=>」4.0000「,」height「=>」0.2500「,」depth「=>」8.0000「,」fixed_cost_shipping_price「=>」0.0000「,」is_free_shipping「=>」false 「,」inventory_tracking「=>」簡單「,」rating_total「=>」0「,」rating_count「=>」0「,」total_sold「=>」0「,」date_created「=>」2014年9月27日,星期六11 :45:14 +0000「, 「brand_id」=>「135」,「view_count」=>「0」,「page_title」=> nil,「meta_keywords」=>「NULL」,「meta_description」=>「NULL」,「layout_file」=> 。html「,」is_price_hidden「=>」false「,」price_hidden_​​label「=> nil,」categories「=> {」value「=>」2「},」date_modified「=>」Sat,27 Sep 2014 11:45: 14 +0000「,」event_date_field_name「=> nil,」event_date_type「=>」none「,」event_date_start「=> nil,」event_date_end「=> nil,」myob_asset_account「=> nil,」myob_income_account「=> 「preorder_release_date」=>「無」,「is_preorder_only」=>「false」,「preorder_message」=「 => nil,「order_quantity_minimum」=>「0」,「order_quantity_maximum」=>「0」,「open_graph_type」=>「product」,「open_graph_title」=> nil,「open_graph_description」=> nil,「is_open_graph_thumbnail」=> 「true」,「upc」=>「714718006338」,「date_last_imported」=> nil,「option_set_id」=>「NULL」,「tax_class_id」=>「0」,「option_set_display」=>「right」,「bin_picking_number」 => nil,「custom_url」=>「/ Opaque-Thigh-High /」,「primary_image」=> {「id」=>「0」,「zoom_url」=>「NULL」,「thumbnail_url」=>「NULL 「,」standard_url「=>」NULL「,」tiny_url「=>」NULL「},」availabili ty「=>」available「,」brand「=> {」link「=> {」content「=>」/ brands/135「,」rel「=>」resource「,」href「=>」https://store-w1w68tq.mybigcommerce.com/api/v2/brands/135.xml 「}},」downloads「=> {」link「=> {」content「=>」/ products/800/downloads「,」rel「=>」resource「,」href「=>」https://store-w1w68tq.mybigcommerce.com/api/v2/products/800/downloads.xml「} },「images」=> {「link」=> {「content」=>「/ products/800/images」,「rel」=>「resource」,「href」=>「https://store-w1w68tq.mybigcommerce.com/api/v2/products/800/images.xml」}}, 「discount_rules」=> {「link」=> {「content」=>「/ products/800/discountrules」,「rel」=>「resource」,「href」=>「https://store-w1w68tq.mybigcommerce.com/api/v2/products/800/discountrules.xml」}},「configurable_fields 「=」{「link」=> {「content」=>「/ products/800/configurablefields」,「rel」=>「resource」,「href」=>「https://store-w1w68tq.mybigcommerce.com/api/v2/products/800/configurablefields.xml」}},「custom_fields」= > {「link」=> {「content「=>」/ products/800/customfields「,」rel「=>」resource「,」href「=>」https://store-w1w68tq.mybigcommerce.com/api/v2/products/800/customfields.xml「}},」videos「=> {」link「=> {」content「=>」/ products/800/videos「,」rel「=>」resource「,」href「=>」https://store-w1w68tq.mybigcommerce.com/api/v2/products/800/videos.xml「}},」skus「=> {」link「=> {」content「 =>「/ products/800/skus」,「rel」=>「resource」,「href」=>「https://store-w1w68tq.mybigcommerce.com/api/v2/products/800/skus.xml」}},「rules」=> {「link」=> {「content」=> 「/ products/800/rules」,「rel」=>「resource」,「href」=>「https://store-w1w68tq.mybigcommerce.com/api/v2/products/800/rules.xml」}},「option_set」=>「NULL」,「options」=> {「link」=> { 「content」=>「/ products/800/options」,「rel」=>「resource」,「href」=>「https://store-w1w68tq.mybigcommerce.com/api/v2/products/800/options.xml」}},「tax_class」=> {「link」=> {「content「=>」/ taxclasses/0 「 」相對「=> 」資源「, 」HREF「=>」 https://store-w1w68tq.mybigcommerce.com/api/v2/taxclasses/0.xml「}}}},

  • 創建選項和選項值;該選項稱爲「顏色」,ID爲25,我想要添加到選項集的值爲;綠色(id 46),黑色(id 45)和紅色(id 44)

    HTTParty。get「({#store_url} options/25」,:basic_auth => @auth)

    =>#{「id」=>「25」,「name」=>「Color」,「display_name」= >「顏色」,「類型」=>「RT」,「值」=> {「link」=> {「content」=>「/ options/25/values」,「rel」=> , 「HREF」=>」 https://store-w1w68tq.mybigcommerce.com/api/v2/options/25/values.xml 「}}}},

選項值:

HTTParty.get("#{@store_url}options/25/values", :basic_auth => @auth) 

=>#{」 值 「=> [{」 ID 「=>」 42" ,「option_id」=>「25」,「label」=>「Gold」,「sort_order」=>「0」,「value」=>「Gold」},{「id」=>「43」,「option_id 「=>」25「,」標籤「 =>「Silver」,「sort_order」=>「0」,「value」=>「Silver」},{「id」=>「44」,「option_id」=>「25」,「label」=>紅色「,」sort_order「=>」0「,」值「=>」紅色「},{」id「=>」45「,」option_id「=>」25「,」label「=>」Black「 「sort_order」=>「0」,「value」=>「Black」},{「id」=>「46」,「option_id」=>「25」,「label」=>「Green」 =>「0」,「value」=>「Green」},{「id」=>「47」,「option_id」=>「25」,「label」=>「White」,「sort_order」=> 0「,」value「=>」White「}]}}

  • 創建一個名爲'111240P'的選項集;其ID是26

    api.create_optionset(:名稱=> 「111204P」)

    { 「ID」=> 26, 「姓名」=> 「111204P」, 「選項」=> { 「URL」 =>「https://store-w1w68tq.mybigcommerce.com/api/v2/optionsets/26/options.json」,「resource」=>「/ optionssets/26/options」}}

  • 將選項鍊接到選項集通過;

     new_option_set_value = api.create_optionset_option(26, options={ 
        :option_id => 25, 
        :display_name => "Colors", 
        :sort_order => 1, 
        :is_required => true 
        }) 
    

返回

{ 「ID」=> 16, 「option_id」=> 25, 「option_set_id」=> 26, 「DISPLAY_NAME」=> 「顏色」, 「排序順序」 => 1,「is_required」=> true,「option」=> {「url」=>「https://store-w1w68tq.mybigcommerce.com/api/v2/options/25.json」,「resource」=>「/ options/25」},「values」=> [{「label」=> >「Gold」,「sort_order」=> 0,「value」=>「Gold」,「option_value_id」=> 42},{「label」=>「Silver」,「sort_order」=> 0, >「Silver」,「option_value_id」=> 43},{「label」=>「Red」,「sort_order」=> 0,「value」=>「Red」,「option_value_id」=> 44},「 「=>」黑色「,」sort_order「=> 0,」value「=>」Black「,」option_value_id「=> 45},{」label「=>」Green「,」sort_order「=> 「=>」綠色「,」選擇這樣,我就去了,然後我走了,我們走了,然後我走了。在問題開始時執行SKU代碼,我會看到提到的錯誤。

我試過16,26和25作爲產品選項ID沒有任何運氣。

SKU資源是我能看到的唯一一個可以讓您將所有這一切與產品聯繫在一起的資源。

任何幫助非常感謝。

更多信息

HTTParty.get("#{@store_url}products/800/options", :basic_auth => @auth) 

=> #<HTTParty::Response:0x10 parsed_response=nil, @response=#<Net::HTTPNoContent 204 No Content readbody=true> 

收出的問題

貝雷帽的意見後一切工作正常。請注意,根據我的理解,以下內容與文檔相反。

撥打電話; 26是我的option_set我連接到產品

 myresponse = HTTParty.put("#{@store_url}products/800", 
     :body=>{ 
      :option_set_id => 26 
      }.to_json, 
      :headers => {'Content-Type' => 'application/json' }, 
     :basic_auth => @auth) 

檢查產品上的選擇:

HTTParty.get("#{@store_url}products/800/options", :basic_auth => @auth) 

響應:

{ 「選項」=> { 「選項」=> {「id」=>「7」,「option_id」=>「25」,「display_name」=>「顏色」,「sort_order」=>「1」,「is_required」=>「true」}}}

回到SKU並添加它,注意產品/選項中的7;

 myresponse = HTTParty.post("#{@store_url}products/800/skus", 
     :body=>{ 
      :sku => "111204", 
      :options => [ 
      { 
       :product_option_id => 7, 
       :option_value_id => 46 
      } 
      ] 
      }.to_json, 
      :headers => {'Content-Type' => 'application/json' }, 
     :basic_auth => @auth) 

響應:

{ 「SKU」=> { 「ID」=> 「7」, 「PRODUCT_ID」=> 「800」, 「SKU」=> 「111204」, 「cost_price」 =>「0.0000」,「upc」=> nil,「inventory_level」=>「0」,「inventory_warning_level」=>「0」,「bin_picking_number」=> nil,「options」=> {「option」=> { 「product_option_id」=>「7」,「option_value_id」=>「46」}}}}

回答

1

product_option_id指的是產品選項ID,請參閱Product Option Resource (API Reference)

您應該能夠通過請求/api/v2/products/800/options.xml

如果上述終點返回空內容得到它,這意味着,該產品尚未與任何選項設置鏈接。您可以通過PUT要求這樣做,通過更新產品/api/v2/products/800像這樣有效載荷: { "option_set_id": 14 }

如果你不知道什麼是option_set_id,結賬:/api/v2/options

四周選項/選項集是這些功能非常通用,最初可能會引起混淆,但另一方面則適用於某些高級場景。

+0

貝雷帽 - 感謝您的光顧。我查看了產品選項資源,但它僅適用於選項的列表/獲取;我看不到如何將它們分配給產品?即我已經在'MORE INFO'中添加了獲取到產品/ 800 /選項。 – gorlaz 2014-10-04 10:11:47

+0

不用擔心@gorlaz,似乎產品還沒有任何選項集分配。我已經添加了一些信息如何做。希望能幫助到你! – petrkotek 2014-10-04 13:25:51

+0

謝謝貝雷帽 - 就是這樣。據docco讀取,option_set是隻讀屬性,'如果請求中包含一個或多個這些屬性,它將被拒絕。'所以你去了,我應該有一個裂縫! (Docco在https://developer.bigcommerce.com/api/stores/v2/products#update-product,更新產品部分) – gorlaz 2014-10-05 09:35:58

相關問題