4

以下に更新

Magento SOAP v1 APIが次のように何かを行うための適切なXMLの例を持っている人はいますか?

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

これは、私には機能しないpythonsuds呼び出しの例です。実際、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のソースを調べて、自分の問題を解決する予定です。

4

4 に答える 4

5

さて、私は自分の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への帽子のヒント。

于 2012-09-12T13:40:06.250 に答える
1

フィルタに間違った形式の配列入力を記述しました。

これが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でイコライズできます。

于 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 に答える