我使用this code为我的rails应用程序使用Magento的API。一切都很好,除了一件事,我需要通过Magento API的参数过滤产品,但我不知道如何:(
显然我已经测试了更多的解决方案(数组,哈希等),但是 不成功。
Pd:对不起,我的英语非常有限
链接
答案 0 :(得分:3)
我知道这已经很晚了,但如果有其他人找到这个帖子,我已经创建了一个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" }])
答案 1 :(得分:3)
花了很多时间与Savon合作 - 网上没有实际的解决方案。去看了SOAP调用并且丢失了:item
params = {:filter => {:item => {:key => "status", :value => "closed"}}}
result = client.call(:sales_order_list, message: { session_id: session_id, filters: params})
这只会返回状态已关闭的订单。
答案 2 :(得分:1)
如果您希望使用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)