2

Magento Store の Android クライアントから Web サービスを呼び出そうとしています。
私は今までうまくいっていますが、ほとんど問題はありません。

この配列を適切な Java オブジェクトに変換する必要があります。

$arrProducts = array(
array(
    "product_id" => "1",
    "qty" => 2
),
array(
    "sku" => "testSKU",
    "quantity" => 4
)
);
$resultCartProductAdd = $proxy->call($sessionId, "cart_product.add", 
                                        array($shoppingCartId, $arrProducts));  

上記の php コードは、here

私が試したこと。

Object []addtocart=null;
Log.i("Product Id ", Utils.product_list.get(rowid).getp_Id());
Object[] productdetails1=new Object[]{Utils.product_list.get(rowid).getp_Id(),2};
//Object[] productdetails2=new Object[]{productdetails1};
Object param1[]=new Object[]{Utils.shoppingCartId,productdetails1};
Object param[]=new Object[]{Utils.sessionId,"cart_product.add",param1};
try {
    addtocart=(Object[])client.callEx("call", param);
} catch (XMLRPCException e) {
    e.printStackTrace();
}

しかし、次のようなエラーが発生します。

org.cws.magentoAnd.xmlrpc.XMLRPCFault: XMLRPC Fault: One item of products do not have identifier or sku [code 1022]
at org.cws.magentoAnd.xmlrpc.XMLRPCClient.callEx(XMLRPCClient.java:228)
at org.cws.magentoAnd.ProductModule.productdetails$CartFunctions.doInBackground(productdetails.java:245)
at org.cws.magentoAnd.ProductModule.productdetails$CartFunctions.doInBackground(productdetails.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)

PHPとJavaの両方の知識を持っている人がこの問題を解決するのを手伝ってくれたら嬉しいです.

4

2 に答える 2

1

If you check the stack trace you will see > One item of products do not have identifier or sku

So the mapping for sku is not getting found. it is also obvious as to why the mapping is not getting found. As the php object is an associative array. The java counterpart for the same is Map.

Now if I was making RPC (WebService based) call using a library like ksoap I would use somthing like PropertyInfo(http://ksoap2.sourceforge.net/doc/api/org/ksoap2/serialization/PropertyInfo.html) to do the mapping between property name and its value. So it depends on the client side library that you are using.

In your code you are using

addtocart=(Object[])client.callEx("call", param); 

It is not eveident from the code snippent as to what is the type of client, so I was not able to guess as to what is the library that you are using, but what ever the library try and look out for some utility classes on the lines PropertyInfo

于 2012-09-18T07:42:06.753 に答える
0

@ sharadendu sinha'sOK、 AnswerからいくつかのアイデアをAssociative Array得て、必要な結果が得られるようなものを Java で作成しました。

コードは以下の通りです。

Map map = new HashMap();
map.put("product_id", 1);
map.put("quantity", 1);
Object[] productdetails1=new Object [] {map};
Object param1[]=new Object[]{Utils.shoppingCartId,productdetails1};
Object param[]=new Object[]{Utils.sessionId,"cart_product.add",param1};
try {
    Object addtocart=client.callEx("call", param);
    Log.i("Out Put of Adding", addtocart.toString());
} catch (XMLRPCException e) {
    e.printStackTrace();
}  
于 2012-09-18T09:55:33.473 に答える