4

下面更新

是否有人为 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'}}]}

在蟒蛇。

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

4

4 回答 4

5

好吧,我不得不刷掉(并学习)我的 PHP,但是如果有任何其他可怜的 sap 出现并想在 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 的提示。

于 2012-09-12T13:40:06.250 回答
1

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

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

$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来平衡它。

于 2012-09-10T08:58:16.820 回答
0

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

PHP:

$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)
于 2013-08-15T14:04:16.023 回答
0

我正在尝试 Python 等价物并不断获得

ValidationError: Missing element for Any 

但是我将过滤器传递给 client.service 方法

于 2020-08-13T19:26:49.813 回答