【问题标题】:Adding a product using Savon to connect to Magento API使用 Savon 添加产品以连接到 Magento API
【发布时间】:2011-11-29 21:35:41
【问题描述】:

我已经获得了在 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

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

(SOAP-ENV:Client) Error cannot find parameter

【问题讨论】:

    标签: ruby magento savon


    【解决方案1】:

    您正在混合使用 array- [] 和 hash-syntax {}

    这就是您收到语法错误的原因(ruby 中没有编译步骤)

    【讨论】:

    • 知道为什么,如果我将代码更改为soap.body = {:session => session, :method => "product.create", ["simple", 1, "testsku1", newproductdata ]} 在这种情况下我得到同样的错误?
    • 啊,newproductdata 需要是哈希吗?
    • 哈希就像 {:key => 'value', ...} 和数组是 ['val1', 'val2', 'val3'] 我想你应该从基础开始在使用一些高级库之前...
    猜你喜欢
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    • 2013-06-27
    相关资源
    最近更新 更多