【发布时间】:2011-11-08 11:33:08
【问题描述】:
我将this code 用于我的带有 Magento API 的 rails 应用程序。一切都很好,除了一件事,我需要通过 Magento API 的参数过滤产品,但我不知道如何:(
显然我已经测试了更多的解决方案(数组、哈希等),但是 不成功。
Pd:对不起,我的英语很有限
链接
【问题讨论】:
标签: ruby-on-rails-3 magento savon
我将this code 用于我的带有 Magento API 的 rails 应用程序。一切都很好,除了一件事,我需要通过 Magento API 的参数过滤产品,但我不知道如何:(
显然我已经测试了更多的解决方案(数组、哈希等),但是 不成功。
Pd:对不起,我的英语很有限
链接
【问题讨论】:
标签: ruby-on-rails-3 magento savon
我知道这已经很晚了,但是如果其他人发现了这个线程,我已经创建了一个 magento_api_wrapper gem,它为 Magento SOAP API v2 实现了过滤器。你可以在这里找到代码:https://github.com/harrisjb/magento_api_wrapper
总而言之,如果您想使用 Magento SOAP API 简单过滤器之一,您可以传递带有键和值的哈希:
api = MagentoApiWrapper::Catalog.new(magento_url: "yourmagentostore.com/index.php", magento_username: "soap_api_username", magento_api_key: "userkey123")
api.product_list(simple_filters: [{key: "status", value: "processing"}, {key: created_at, value: "12/10/2013 12:00" }])
要使用复杂的过滤器,请传递带有键、运算符和值的哈希:
api.product_list(complex_filters: [{key: "status", operator: "eq", value: ["processing", "completed"]}, {key: created_at, operator: "from", value: "12/10/2013" }])
【讨论】:
花了很长时间才让它与 Savon 一起工作 - 网络上没有实际的解决方案。去查看 SOAP 调用,发现丢失了:item
params = {:filter => {:item => {:key => "status", :value => "closed"}}}
result = client.call(:sales_order_list, message: { session_id: session_id, filters: params})
这只会返回状态为已关闭的订单。
【讨论】:
[{:filter => {:item => {:key => "status", :value => "1"}}}, {:filter => {:item => {:key => "type", :value => "grouped"}}}] 不起作用。它只是应用列表中的第一个过滤器
filters: [{:filter=>{:item=>[{:key=>"status", :value=>"1"}, {:key=>"type", :value=>"simple"}]}}] 适用于多个过滤器
如果您希望使用 Magento 和 Rails,Gemgento 可能是您所需要的。它用 RoR 替换了 Magento 的前端。
与 Magento 同步后,您可以使用 Gemgento::Product.filter 方法和一些范围轻松搜索 Magento 的 EAV 结构。
attribute = Gemgento::Attribute.find_by(code: 'color')
Gemgento::Product.filter({ attribute: attribute, value: 'red' })
filter 方法实际上可以采用各种数组/哈希组合
filters = [
{ attribute: [attribute1, attribute2], value: %w[red yellow black] },
{ attribute: size_attribute, value: 'L' }
]
Gemgento::Product.filter(filters)
【讨论】: