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

2024-04-28 13:47:21 发布

您现在位置:Python中文网/ 问答频道 /正文

更新如下

有没有人可以为magentosoapv1api提供一个合适的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的sud和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>

当然,我已经尝试了上百万种其他的变体。我只是想知道我的调用是否正确,我有一个坏的模式,或者soap服务器是否不稳定,或者什么。因此,如果任何人有一些被证明是正确的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源代码中找到根并解决我自己的问题。


Tags: orgenvhttpstringvaluetypeargsorder
3条回答

您为筛选器编写了错误的格式数组输入。

我想,如果这是php的解决方案的话。

$params = array(array(
            'filter' => array(
                array(
                    'key' => 'status',
                    'value' => 'pending'
                ),
                array(
                    'key' => 'created_at',
                    'value' => '2001-11-25 12:12:07',
                )
            ),
            'complex_filter' => array(
                array(
                    'key' => 'order_id',
                    'value' => array(
                        'key' => 'in',
                        'value' => '12,23'
                    ),
                ),
                array(
                    'key' => 'protect_code',
                    'value' => array(
                        'key' => 'eq',
                        'value' => 'ebb2a0'
                    ),
                ),
            )
        ));

$result = $client->__call('salesOrderList', $params);

你可以用python来平衡它。

好吧,我不得不拒绝(并学习)我的PHP,但我有答案,如果有任何其他可怜的sap出现,并想使用sud(或一般python)与Magento。

此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相关的编码问题——看起来它是设计用来与phpsoap客户机一起工作的,但实际上不是与其他任何东西一起工作的。但这个XML转储确实让我可以四处闲逛,把SUDS连接从地上取下来——如果你有兴趣的话,给我发个消息。哦,还有给“阿兰斯托姆”的帽子。

我知道这个问题是关于API的v1,但是如果您使用v2,您可以这样做:

菲律宾比索:

$complexFilter = array(
    'complex_filter' => array(
        array(
            'key' => 'type',
            'value' => array('key' => 'in', 'value' => 'simple,configurable')
        )
    )
);
$result = $client->catalogProductList($session, $complexFilter);

Python等价物:

complex_filter = [{'complex_filter': [{
    'key': 'type',
    'value': [{
        'key': 'in',
        'value': 'simple,configurable'}]
    }]
}]
client.service.catalogProductList(session, complex_filter)

相关问题 更多 >