Filter products with API Magento in Ruby on Rails with Savon gem (SOAP) - ruby-on-rails-3

I am using this code 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
Links
Related case (fail): Adding a product using Savon to connect to Magento API
Example: http://www.polyvision.org/2011/10/02/using-magento-soap-api-with-ruby-and-savon.html

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
To summarize, if you want to use one of the Magento SOAP API simple filters, you can pass a hash with a key and value:
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" }])
And to use a complex filter, pass a hash with key, operator, and value:
api.product_list(complex_filters: [{key: "status", operator: "eq", value: ["processing", "completed"]}, {key: created_at, operator: "from", value: "12/10/2013" }])

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.

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)

Related

API Platform - Get collection where Author is User

I currently have an Offer entity which has an author property, like so :
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'offers')]
#[ORM\JoinColumn(nullable: false)]
private $author;
Currently, when I do a get request on /offers/, I get a collection of ALL the offers, which is normal.
I would want to only retrieve the offers where the author is the logged in user instead. (basically a findBy(['author'=>$this->getUser()]))
After searching on the internet I've been trying the following, which obviously is not working
#[ORM\Entity(repositoryClass: OfferRepository::class)]
#[ApiResource(
normalizationContext: [
'groups' => ['read'],
],
itemOperations: [
'get' => [
'security' => 'object.author == user',
]
],
collectionOperations: [
'get' => [
'security' => 'object.author == user',
]
]
)]
class Offer
{
...
This gives me the following error :
hydra:description: "Warning: Undefined property:
ApiPlatform\Core\Bridge\Doctrine\Orm\Paginator::$author"
Which tells me this is completely the wrong approach.
Kind of stuck here, any hint ?
Thank you.
Maybe a bit late but this is answered by implementing an "extension". That would allow the collection to be filtered to match only items with a specific condition (in your case, a User).
There's an old issue (here: https://github.com/api-platform/core/issues/1481).
And official documentation here: https://api-platform.com/docs/core/extensions/#example.

Many-To-Many Association on Same Model using Waterline & Sails.js [duplicate]

I'm pretty new on Nodejs and sails.
I'm implementing a server which is similiar to Twitter. In user model, there should be 2 fields: follower and following, and the 2 fields are association of the model 'user' itself.
My question is when the model have only 1 association, either follower or following, it works.
However, when both follower and following included, there would be en error.
The code is something like this:
module.exports = {
attributes: {
alias: {
type:'string',
required: true,
primaryKey: true
},
pwd: {
type: 'string',
required: true
},
follower: {
collection: 'user',
via: 'alias'
},
following:{
collection: 'user',
via: 'alias'
}
}
The code will cause such error:
usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/references.js:115
throw new Error('Trying to associate a collection attribute to a model tha
^
Error: Trying to associate a collection attribute to a model that doesn't have a Foreign Key. user is trying to reference a foreign key in user
at References.findReference (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/references.js:115:11)
at References.addKeys (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/references.js:72:22)
For such usage your model definition is incorrect, namely the via keywords. As per the waterline associations docs the via keyword references the other side of the association. So, for a follower the other side is following and vice-versa. In other words:
follower: {
collection: 'user',
via: 'following'
},
following:{
collection: 'user',
via: 'follower'
}
You can check a full working example at: https://github.com/appscot/sails-orientdb/blob/master/test/integration-orientdb/tests/associations/manyToMany.selfReferencing.js

How to use an API

I'm studying Informatics but somehow I don't get that one.
I want to set up the PayPal NVP-API.
(NVP = Name value Pair).
Can someone tell me how I can CALL an API-Command?
I don't even know which programming language I have to take :S
Reference to the Tutorial: PayPal NVPAPI Developer Guide
It sounds like you might be a bit over your head on this one, but don't worry it's not that difficult.
When they say POST they literally mean an HTTP POST, but since its SSL you'd need to provide credentials also.
jQuery AJAX http://api.jquery.com/jQuery.ajax/ would be a good place to start..
$.ajax({
url : 'paypalurl',
type : 'POST', //IMPORTANT
username : 'username',
password : 'password',
data : 'YOUR DATA HERE' //form or something of the like
success : function(r) {
//handle the success here
},
error : function(e) {
//uh-oh
}
});
This should get you started, but please be careful this is financial data.

How do I use the Rails Vacuum Gem and get XML from the response

I am trying to fool around with the Vacuum gem, but I have some issues with the example. When I run the code as described on the frontpage:
req = Vacuum.new
req.configure key: 'foo',
secret: 'secret',
tag: 'biz-val'
params = { 'Operation' => 'ItemSearch',
'SearchIndex' => 'Books',
'Keywords' => 'Architecture' }
res = req.get query: params # XPath is your friend.
I am having issues getting the XML from the response. I can see that the object type is Excon::Response and actually contains data, but how do I retrieve the XML it contains?
I have tried with both res.to_xml and res.xml, and even loading it into Nokogiri, but with no success.
I found out. XML was saved in the object Body in the response.

Random numbers added to extjs data store ajax call

var resource_store = Ext.create('Ext.data.Store', {
pageSize: 10,
autoLoad: true,
fields: ['id','r_number','c_number','resource_name','resource_desc','resource_url','resource_file'],
proxy: {
type: 'ajax',
url: BASE_URL+'courses/resources/displayResources/'+course_id,
reader: {
type: 'json',
root: 'results'
}
},
storeId: 'id'
});
I'm using Extjs4 data store like this way.
When i see the ajax calls a random number is appended to the url
http://localhost/Edu_web/index.php/courses/resources/displayResources/PTGRE14?_dc=1328442262503&page=1&start=0&limit=10
Even though i use
actionMethod:{
read: 'POST'
}.
?_dc=1328442262503 still appears in the url.
how to remove these parameters in url. and send any parameters through POST
Even though i use actionMethod:{ read: 'POST' }.
?_dc=1328442262503 still appears in the url.
Of course it would. You should use actionMethods (with 's' at the end).
To remove _dc from GET request you should add noCache: false to proxy's config. Docs for noCache.
P.S. Using a POST for reading is a bad practise. You should only use a POST when you are modifying data on the server.
If there are any proxy in your network, before disabling the random number, check to see if they have caching disabled, otherwise the client, instead of downloading the updated pages from the server, will continue to read the previous ones stored in the proxy. The random number added to the call makes it different each time and the proxy will be forced to always download it from the server