2011-11-08 36 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」}]}}]'適用於多個過濾器 –