Filter products with API Magento in Ruby on Rails with Savon gem (SOAP)
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" }])
How to use the savon gem with Magento SOAP API
C# Example of using Magento's API:
The same applies to any other language including ruby. Obviously the syntax will differ and i'm assuming you know the Savon syntax already.
You may also want to checkout: https://github.com/timmatheson/Magento#readme
How do I correctly call Magento SOAP API with Ruby Savon for Category Product Links?
I was able to get this to work using Builder:
class ServiceRequest
def initialize(session, type, product)
@session = session
@type = type
@product = product
end
def to_s
builder = Builder::XmlMarkup.new()
builder.instruct!(:xml, encoding: "UTF-8")
builder.tag!(
"env:Envelope",
"xmlns:env" => "http://schemas.xmlsoap.org/soap/envelope/",
"xmlns:ns1" => "urn:Magento",
"xmlns:ns2" => "http://xml.apache.org/xml-soap",
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance"
) do |envelope|
envelope.tag!("env:Body") do |body|
body.tag!("ns1:call") do |call|
builder.sessionId(@session, "xsi:type" => "xsd:string")
builder.resourcePath("catalog_product_link.list", "xsi:type" => "xsd:string")
builder.args("xsi:type" => "ns2:Map") do |args|
args.item do |item|
item.key("type", "xsi:type" => "xsd:string")
item.value(@type, "xsi:type" => "xsd:string")
end
args.item do |item|
item.key("product", "xsi:type" => "xsd:string")
item.value(@product, "xsi:type" => "xsd:string")
end
end
end
end
end
builder.target!
end
end
client.call(:call, xml: ServiceRequest.new(session, 'up_sell', '166').to_s)
Thanks to @rubiii for the direction.
Add a configurable product to Magenta cart using SOAP V2 (Savon gem)
Finally, I got it,
I've added to the shoppingCarteProductEntity
in: wsi.xml
and wsdl.xml
the line :
<element name="super_attribute" type="typens:associativeArray" minOccurs="0"/>
shoppingCartProductEntity
:
<complexType name="shoppingCartProductEntity">
<all>
<element name="product_id" type="xsd:string" minOccurs="0"/>
<element name="sku" type="xsd:string" minOccurs="0"/>
<element name="qty" type="xsd:double" minOccurs="0"/>
<element name="options" type="typens:associativeArray" minOccurs="0"/>
<element name="super_attribute" type="typens:associativeArray" minOccurs="0"/>
<element name="bundle_option" type="typens:associativeArray" minOccurs="0"/>
<element name="bundle_option_qty" type="typens:associativeArray" minOccurs="0"/>
<element name="links" type="typens:ArrayOfString" minOccurs="0"/>
</all>
</complexType>
Then (and it's the most important part), here's the way to call with Savon gem :
# ...
# Before we initialize client, session_id, quote_id...
product_data = {
'product_id' => 123,
'sku' => 'MYSKU',
'qty' => 1,
'super_attribute' => [
[
{
key: '537',
value: '57'
},
{
key: '549',
value: '66'
}
]
]
}
res = client.call(:shopping_cart_product_add, message: {sessionId: session_id, quoteId: quote_id, products: {item: [product_data] }})
Magento SOAP API v2: Setting product options in cart
Encountered a similar problem and the solution can be found in this answer - Setting Custom Options while adding a product to cart via SOAP in Magento
The example code given on Magento's SOAP page for cart_product.add is faulty.
How to create subcategories in Magento using API SOAP?
$category = Mage::getModel('catalog/category');
$category->setStoreId(0); // 0 = default/all store view. If you want to save data for a specific store view, replace 0 by Mage::app()->getStore()->getId().
//if update
if ($id) {
$category->load($id);
}
$general['name'] = "My Category";
$general['path'] = "1/3/"; // catalog path here you can add your own ID
$general['description'] = "Great My Category";
$general['meta_title'] = "My Category"; //Page title
$general['meta_keywords'] = "My , Category";
$general['meta_description'] = "Some description to be found by meta search robots. 2";
$general['landing_page'] = ""; //has to be created in advance, here comes id
$general['display_mode'] = "PRODUCTS"; //static block and the products are shown on the page
$general['is_active'] = 1;
$general['is_anchor'] = 0;
$general['page_layout'] = 'two_columns_left';
//$general['url_key'] = "cars";//url to be used for this category's page by magento.
//$general['image'] = "cars.jpg";
$category->addData($general);
try {
$category->setId(255); // Here you cant set your own entity id
$category->save();
echo "Success! Id: ".$category->getId();
}
catch (Exception $e){
echo $e->getMessage();
}
Related Topics
How to Collect Real-Time Tweets
Refactoring Pokemon Type Weekness
Newbie: Text Replacement in My Case
Removing All Installed Gems and Starting Over
Ror: How to Get My Microposts to Show Up
How to Use Local or Instance Variable in Ruby Code in Coffeescript in Haml Template
Rails 3 - Devise/Actionmailer/Ruby-Smtp Causing a Segmentation Fault
How to Get Data from Database in Ruby
Making Hashes Find Each Other by Their Values Using Ruby
Ruby Parallel Assignment, Step Question
How to Remove the Extra Double Quote
Installed Memcached via Homebrew, How to Start and Stop Server