3

我正在将此代码用于我的 Rails 应用程序和 Magento 的 API。一切都很好,除了一件事,我需要通过 Magento API 的参数过滤产品,但我不知道如何:(

显然我已经测试了更多的解决方案(数组、哈希等),但没有成功。

Pd:对不起,我的英语很有限

链接

4

3 回答 3

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" }])
于 2014-02-28T18:44:47.500 回答
3

花了很长时间才让它与 Savon 一起工作 - 网络上没有实际的解决方案。去查看了 SOAP 调用,结果不见了:item

params = {:filter => {:item => {:key => "status", :value => "closed"}}}

result = client.call(:sales_order_list, message: { session_id: session_id, filters: params})

这只会返回状态为已关闭的订单。

于 2016-03-22T22:14:50.217 回答
1

如果您希望使用 Magento 和 Rails,Gemgento 可能是您需要的。它用 RoR 代替了 Magento 的前端。

http://www.gemgento.com

与 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)
于 2014-07-07T20:55:33.737 回答