使用Savon添加产品以连接到Magento API

时间:2011-10-03 12:24:52

标签: ruby magento savon

我已经有代码在Ruby中列出产品,但我很难添加产品,这是我的代码,我正在使用savon gem来获取HTTP / SOAP请求,基于此处的代码http://www.polyvision.org/2011/10/02/using-magento-soap-api-with-ruby-and-savon/

# Insert some products ...

newproductdata = [ 
["name" , “test product"], 
["websites" , [1]], 
["short_description" , ‘short description’], 
["description" , ‘description’], 
["status" , 1], 
["weight" , 0], 
["tax_class_id" , 1], 
["categories" , [3]], 
["price" , 12.05] 
]

begin 
  response = client.request :call do 
    soap.body = {:session => session, :method => “product.create”, :arguments => ["simple", 1, “testsku1”, newproductdata]} 
  end 
rescue Savon::SOAP::Fault => fault 
  puts “*****#{fault.to_s}*****” 
end

我认为问题是传入:可能需要正确命名的参数,此代码会生成错误,

(SOAP-ENV:Client) Error cannot find parameter

1 个答案:

答案 0 :(得分:2)

你正在混合array- []和hash-syntax {}

这就是你收到SYNTAX错误的原因(ruby中没有COMPILATION步骤)