magja/magja — Issue #23: 23 - OrderFilter serialize bug (and fix) 
Author: ceefour
Created: 2011-11-02 11:33:13+00:00
State: open

What steps will reproduce the problem?
1. adding a filter to a call to OrderRemoteService.list()
2.
3.

What is the expected output? What do you see instead?
The returned list should be filtered, but all orders are returned.

What version of the product are you using? On what operating system?
I'm working with r303 from SVN

Please provide any additional information below.

The SOAP request with 2 filters: (not working)
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<mag:call xmlns:mag="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-XML="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<sessionId>---</sessionId>
<resourcePath>sales_order.list</resourcePath>
<args SOAP-ENC:arrayType="xsd:ur-type[4]" xsi:type="SOAP-ENC:Array">
<item xsi:type="xsd:string">subtotal</item>
<item xsi:type="SOAP-XML:Map">
<item>
<key xsi:type="xsd:string">&gt;</key>
<value xsi:type="xsd:string">300.00</value>
</item>
</item>
<item xsi:type="xsd:string">customer_firstname</item>
<item xsi:type="SOAP-XML:Map">
<item>
<key xsi:type="xsd:string">eq</key>
<value xsi:type="xsd:string">Jacob</value>
</item>
</item>
</args>
</mag:call>
</soapenv:Body>
</soapenv:Envelope>

The SOAP request from PHP code optained from magento API documentation: (working)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:call>
<sessionId xsi:type="xsd:string">---</sessionId>
<resourcePath xsi:type="xsd:string">sales_order.list</resourcePath>
<args SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">customer_firstname</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">Like</key>
<value xsi:type="xsd:string">John</value>
</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">customer_lastname</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">eq</key>
<value xsi:type="xsd:string">Doe</value>
</item>
</value>
</item>
</item>
</args>
</ns1:call>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

As seen the structure of the XML is different, so i changed the OrderFilter.serializeToApi() to the following:

public Object serializeToApi() {
List<Object> props = new LinkedList<Object>();
for (OrderFilterItem item : items) {
Map<String, Map> filterItem = new HashMap<String, Map>();
Map<String, String> params = new HashMap<String, String>();
params.put(item.getOperator(), item.getValue());
filterItem.put(item.getProperty(), params);
props.add(filterItem);
}

return props;
}

Then it worked, and the SOAP request looks like:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<mag:call xmlns:mag="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-XML="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<sessionId>---</sessionId>
<resourcePath>sales_order.list</resourcePath>
<args SOAP-ENC:arrayType="xsd:ur-type[2]" xsi:type="SOAP-ENC:Array">
<item xsi:type="SOAP-XML:Map">
<item>
<key xsi:type="xsd:string">subtotal</key>
<value xsi:type="SOAP-XML:Map">
<item>
<key xsi:type="xsd:string">gt</key>
<value xsi:type="xsd:string">300.00</value>
</item>
</value>
</item>
</item>
<item xsi:type="SOAP-XML:Map">
<item>
<key xsi:type="xsd:string">customer_firstname</key>
<value xsi:type="SOAP-XML:Map">
<item>
<key xsi:type="xsd:string">eq</key>
<value xsi:type="xsd:string">Jacob</value>
</item>
</value>
</item>
</item>
</args>
</mag:call>
</soapenv:Body>
</soapenv:Envelope>

Original link: http://code.google.com/p/magja/issues/detail?id=23