2011-11-08 35 views
3

我使用this code为我的rails应用程序提供了Magento的API。一切都很好,除了一件事,我需要通过Magento API的参数过滤产品,但我不知道如何:(在带有Savon gem(SOAP)的Ruby on Rails中过滤带API Magento的产品

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

钯:对不起,我的英语是非常有限的

链接

回答

3

我知道这是非常晚的,但如果其他人是找到这个线程,我已经创建了一个用于Magento的SOAP API V2实现过滤器magento_api_wrapper宝石。您可以在这里找到代码: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

如果您正在寻找与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' }) 

过滤方法实际上可以采取各种阵列/散列连击

filters = [ 
    { attribute: [attribute1, attribute2], value: %w[red yellow black] }, 
    { attribute: size_attribute, value: 'L' } 
] 
Gemgento::Product.filter(filters) 
+0

虽然价格昂贵。 – snowangel

3

花了年龄越来越这与莎翁工作的 - 有在网络上没有实际的解决方案。去看看SOAP调用并丢失:项目

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

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

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

+1

太棒了!工作给我!何时需要应用多个过滤器? –

+0

它适用于我的目录产品列表API。谢谢!! 正如@IsmaelVacco提到的,不知道如何使用多个过滤器。尝试'[{:filter => {:item => {:key =>“status”,:value =>“1”}}},{:filter => {:item => {:key =>“type “,:value =>”分组“}}}]'不起作用。它只是应用列表中的第一个过滤器 –

+0

'filters:[{:filter => {:item => [{:key =>“status”,:value =>“1”},{:key =>“type” ,:value =>“simple”}]}}]'适用于多个过滤器 –