11

Magento から XMLRPC を使用して Androidで複数の製品の詳細を取得する方法Single Call.XMLRPC を使用した関数を使用して、製品のリストを取得できますcatalog_product.list

これで、すべての製品のSKU ID を取得できました。関数を使用して、各製品のメディアの詳細を取得できますproduct_media.list

10 個の製品があると仮定すると、製品ごとに 10 回のメソッドを呼び出さなければならず、product_media.list時間がかかります。

では、 AndroidでのmultiCall関数をどのように呼び出すことができますか。関数を呼び出すためMagentoの多くのチュートリアルが投稿されていますが、Android で同じことを模倣することはできません。phpmultiCall

multiCallそのため、関数(Android用)を理解できる同様のコードスニペットがあれば、それを使用してさらに進めることができます。
ありがとう。


Josua Marcel Cの回答からの PHP コードの例:


$session = $client->call('login', array('apiUser', 'apiKey'));
$client->call('call', array($session,'somestuff.method', array('arg1', 'arg2', 'arg3')));  
$client->call('call', array($session, 'somestuff.method', 'arg1'));   
$client->call('call', array($session, 'somestuff.method'));

$client->call('multiCall', 
               array($session,
                  array(
                      array('somestuff.method', 'arg1'),
                      array('somestuff.method', array('arg1', 'arg2')),
                      array('somestuff.method')
                   )
              )
            );  

multiCall()Magentoの関数を呼び出す Android の上記の php コードを模倣したいと思います。


4

3 に答える 3

3

長い間研究を重ねた結果、メソッドを何もせずに呼び出す中途半端なソリューションを手に入れましたが、それでも変数内 のの応答を取得して使用する方法がわかりません。multiCall()ErrorServer

それを知っている人なら誰でも私の答えを編集することができます、私は彼に感謝します。

Code私が使用した のは:

Object[] skuid=new Object[product_list.size()];
Object calling[]=new Object[product_list.size()];

for(int m=0;m<product_list.size();m++)
{
    skuid[m]=new Object[]{product_list.get(m).getp_Sku()};
    calling[m]=new Object[]{"catalog_product_attribute_media.list",skuid[m]};   
}

try 
{
  client.callEx("multiCall",new Object[]{Utils.sessionId,calling});
}
catch (XMLRPCException e) 
{
    e.printStackTrace();
}  

謝辞:

によって投稿された回答に取り組んできました Iain

于 2012-08-29T10:52:53.030 に答える
2

答え

androidはJavaアプリをベースにしているので、これが使えます。

package org.apache.xmlrpc;

import java.util.Hashtable;
import java.util.Vector;

public class MultiCall
implements ContextXmlRpcHandler
{
    public Object execute(String method, Vector params, XmlRpcContext context)
            throws Exception
    {
        if ("multicall".equals(method))
        {
            return multicall(params, context);
        }

        throw new NoSuchMethodException("No method '" + method + "' in " + this.getClass().getName());
    }

    public Vector multicall(Vector requests, XmlRpcContext context)
    {
        // The array of calls is passed as a single parameter of type array.
        requests=(Vector)requests.elementAt(0);
        Vector response = new Vector();
        XmlRpcServerRequest request;
        for (int i = 0; i < requests.size(); i++)
        {
            try
            {
                Hashtable call = (Hashtable) requests.elementAt(i);
                request = new XmlRpcRequest((String) call.get("methodName"),
                                            (Vector) call.get("params"));
                Object handler = context.getHandlerMapping().getHandler(request.getMethodName());
                Vector v = new Vector();
                v.addElement(XmlRpcWorker.invokeHandler(handler, request, context));
                response.addElement(v);
            }
            catch (Exception x)
            {
                String message = x.toString();
                int code = (x instanceof XmlRpcException ?
                            ((XmlRpcException) x).code : 0);
                Hashtable h = new Hashtable();
                h.put("faultString", message);
                h.put("faultCode", new Integer(code));
                response.addElement(h);
            }
        }
        return response;
    }
}

ソース


Magento は SOAP API をサポートしているのに、SOAP API v1 を使用しなかったのはなぜですか? SOAP は強力だからです。ここに行ってみてくださいXML-RPC と SOAP の違いは何ですか?

Soap メッセージの解析は Android ランタイムには含まれていないため、単純ではありません。外部ライブラリを使用する必要があります。ksoap2 を使用しています。

ここでStackOverflowを検索すると、その使用方法に関する多くの例が表示されます。たとえばここ

その他の参照:リンク 1 リンク 2

PHP を使用したマルチコール

$client = new Zend_XmlRpc_Client('http://magentohost/api/xmlrpc/');

// If somestuff requires api authentification,
// we should get session token
$session = $client->call('login', array('apiUser', 'apiKey'));

$client->call('call', array($session, 'somestuff.method', array('arg1', 'arg2', 'arg3')));
$client->call('call', array($session, 'somestuff.method', 'arg1'));
$client->call('call', array($session, 'somestuff.method'));
$client->call('multiCall', array($session,
     array(
        array('somestuff.method', 'arg1'),
        array('somestuff.method', array('arg1', 'arg2')),
        array('somestuff.method')
     )
));

// If you don't need the session anymore
$client->call('endSession', array($session));
于 2012-08-19T04:01:43.683 に答える
1

まず、catalog_product.listを呼び出すために機能する方法でログインします。を確認し、session正しい値を設定してください。これらの操作のためにログインする必要がない場合は、を設定します(それが機能しない場合は、セッションをまったく渡さないようにしてください:))。それで:clientproduct_idssession = null

Object[][] calls = new Object[product_ids.length];
for (int i = 0; i < product_ids.length; i++) {
    calls[i] = new Object[] { "product_media.list", product_ids[i] };
}
product_media_ids = client.call("multiCall", new Object[] { session, calls });

product_media_idsその場合、商品画像の配列の配列である必要があります。つまり、の各要素はproduct_media_idsからの戻り値になりますproduct_media.list

コードはテストされていません、私は恐れています。

于 2012-08-20T08:31:22.737 に答える