Filtrar productos con API Magento en Ruby on Rails con Savon gem (SOAP)

Estoy utilizando este codigo for my rails app with the API of Magento. Everything is fine except for one thing, i need filter the products by arguments of the Magento API but i don't know how :(

Obviously i have tested with more solutions (array, hash, etc), but unsuccessful.

Pd: Sorry, my english is very limited

Enlaces

preguntado el 08 de noviembre de 11 a las 11:11

3 Respuestas

I know this is very late, but if anyone else is finding this thread, I've created a magento_api_wrapper gem that implements filters for the Magento SOAP API v2. You can find the code here: https://github.com/harrisjb/magento_api_wrapper

En resumen, si desea utilizar uno de los filtros simples de la API SOAP de Magento, puede pasar un hash con una clave y un valor:

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" }])

Y para usar un filtro complejo, pase un hash con clave, operador y valor:

api.product_list(complex_filters: [{key: "status", operator: "eq", value: ["processing", "completed"]}, {key: created_at, operator: "from", value: "12/10/2013" }])

Respondido 28 Feb 14, 22:02

Spent ages getting this to work with Savon - there are no actual solutions on the web. Went and looked at the SOAP call and was missing :item

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

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

This will only return orders that are of status closed.

respondido 23 mar '16, 01:03

great! Work to me! when is need apply more than one filter? - Ismael Vacco

It worked for me for catalog product list API. Thanks!! As @IsmaelVacco mentioned, not sure how to use multiple filters. Trying [{:filter => {:item => {:key => "status", :value => "1"}}}, {:filter => {:item => {:key => "type", :value => "grouped"}}}] doesn't work. It just applies first filters from the list - Amit Patel

filters: [{:filter=>{:item=>[{:key=>"status", :value=>"1"}, {:key=>"type", :value=>"simple"}]}}] worked for multiple filters - Amit Patel

If you are looking to work with Magento and Rails, Gemgento might be what you need. It replaces Magento's front end with RoR.

http://www.gemgento.com

After you sync with Magento you can use the Gemgento::Product.filter method along with some scopes to easily search the EAV structure of Magento.

attribute = Gemgento::Attribute.find_by(code: 'color')
Gemgento::Product.filter({ attribute: attribute, value: 'red' })

The filter method can actually take all sorts of array/hash combos

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

Respondido 08 Jul 14, 00:07

Massively expensive though. - Ángel de nieve

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.