编程语言
首页 > 编程语言> > Magento SOAP v1过滤器不过滤(Python Suds)

Magento SOAP v1过滤器不过滤(Python Suds)

作者:互联网

更新如下

有没有人为Magento SOAP v1 API提供适当的XML示例,以便按照以下方式执行某些操作?

client.call(session_token,'sales_order.list', {'filters':{'order_id':{'eq':12}}})

这是一个不适合我的python suds调用的例子.实际上,任何过滤sales_order.list,catalog_product.list或customer.list的示例XML都可以.我已经为XMLRPC版本工作,但是使用python的SUDS和SOAP v1 API,无论过滤器是什么,我都会将整个列表作为响应进行过滤.这是XML目前的样子:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="urn:Magento" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns4:call>
<sessionId xsi:type="ns2:string">6634e1bd1004557677222fd81e809884</sessionId>
<resourcePath xsi:type="ns2:string">sales_order.list</resourcePath>
<args xsi:type="ns0:args">
<filters xsi:type="ns2:filters">
<order_id xsi:type="ns2:order_id">
<eq xsi:type="ns2:string">7</eq>
</order_id>
</filters>
</args>
</ns4:call>
</ns1:Body>

当然,我已经在上面尝试了一百万个其他变种.我只是想知道我的电话是否正确,我的架构是坏的,或者肥皂服务器是不是很糟糕,或者是什么.因此,如果任何人都有一些经过验证的正确XML来尝试模拟,那么它会有很多帮助.

谢谢!

更新:

根据我到目前为止收到的第一个答案,我实际上已经尝试过滤镜的格式了.正如我们所知,Magento API的文档是多种多样的,冲突的和不完整的.这是XML:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="urn:Magento" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns4:call>
<sessionId xsi:type="ns2:string">93c7aaab38adaab5db732b211e5b</sessionId>
<resourcePath xsi:type="ns2:string">sales_order.list</resourcePath>
<args xsi:type="ns0:args">
<filter xsi:type="ns2:filter">
<value xsi:type="ns2:string">123</value>
<key xsi:type="ns2:string">order_id</key>
</filter>
</args>
</ns4:call>
</ns1:Body>
</SOAP-ENV:Envelope>

或者可能:

<ns1:Body>
<ns4:call>
<sessionId xsi:type="ns2:string">93c74cb7ef0baaaaab5db732b211e5b</sessionId>
<resourcePath xsi:type="ns2:string">sales_order.list</resourcePath>
<args xsi:type="ns0:args">
<filter xsi:type="ns2:filter">
<value xsi:type="ns2:value">
<value xsi:type="ns2:string">123</value>
<key xsi:type="ns2:string">eq</key>
</value>
<key xsi:type="ns2:string">order_id</key>
</filter>
</args>
</ns4:call>
</ns1:Body>
</SOAP-ENV:Envelope>

看起来像这样:

{'filter':[{'key':'order_id','value':{'key':'eq','value':'123'}}]}

在python中.

那些仍然返回所有订单(最终……).因此,正如我所提到的,如果任何人实际上可以给我一些XML来模拟,那么它可能会更有用.我明天可能会通过Magento来源并解决我自己的问题.

解决方法:

好吧,我不得不刷掉(并学习)我的PHP,但是我有答案,如果有任何其他可怜的傻瓜出现并希望使用Magento的SUDS(或一般的python).

这个xml:

<?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">bc11488aaae84c841ac237ea7f24ef</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">order_id</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">from</key>
<value xsi:type="xsd:string">11</value>
</item>
<item>
<key xsi:type="xsd:string">to</key>
<value xsi:type="xsd:string">12</value>
</item>
</value>
</item>
</item>
</args>
</ns1:call>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

是由这个PHP创建的:

#! /usr/bin/php5
<?php
$client = new SoapClient('http://ip.ip.ip.ip/magento/index.php/api/?wsdl', array('trace'=>TRUE));
$session = $client->login('username', 'password');
$params = array(array(
        'order_id' =>
          array(
            'from' => '10',
            'to' => '12')));



$result = $client->call($session, 'sales_order.list', $params);
$resultXML = $client->__getLastRequest();
print($resultXML);
?>

当然,事实证明,围绕Magento特定的协议实现存在各种与SOAP相关的编码问题 – 似乎它的设计与PHP Soap客户端一起使用,但实际上并没有与其他任何东西一起使用.但是这个XML转储确实允许我破解并从地面获得SUDS连接 – 如果你很好奇,请给我发消息.哦,给@alanstorm的帽子小费.

标签:python,soap,magento,api,suds
来源: https://codeday.me/bug/20190529/1181734.html