我正在使用magento api“shoppingCartProductRemove”从购物车中删除商品。 在“shoppingCartProductEntity”中,它需要“associativeArray”。如何创建“associativeArray”以及其中的Product自定义选项。 我正在尝试
SoapObject item = new SoapObject(NAMESPACE,"shoppingCartProductEntity");
PropertyInfo pinfo = new PropertyInfo();
String productid = productId.get(deleteProductPosition);
pinfo.setName("product_id");
pinfo.setValue(productid);
pinfo.setType(String.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
String productsku = productSku.get(deleteProductPosition);
pinfo.setName("sku");
pinfo.setValue(productsku);
pinfo.setType(String.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
int productQty = Qty.get(deleteProductPosition);
pinfo.setName("qty");
pinfo.setValue(productQty);
pinfo.setType(Double.class);
item.addProperty(pinfo);
Map<String, String> map = new HashMap<String, String>();
map.put("key", "options");
pinfo = new PropertyInfo();
pinfo.setName("options");
pinfo.setValue(map.get("key"));
pinfo.setType(Map.class);
item.addProperty(pinfo);
如何使用选项创建关联数组,以及该数组的setType是什么。请让我知道
答案 0 :(得分:1)
首先阅读此Module: Shopping Cart API
请参阅此网址上给出的给定示例代码。
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$result = $proxy->shoppingCartProductRemove($sessionId, 10, array(array(
'product_id' => '4',
'sku' => 'simple_product',
'qty' => '1',
'options' => null,
'bundle_option' => null,
'bundle_option_qty' => null,
'links' => null
)));
var_dump($result)
关联数组是使用您指定给它们的命名键的数组。
也可以参考关联数组:
添加了参考链接:(Java)据我所知,java不支持关联数组,但您可以通过引用以下URL来实现。
答案 1 :(得分:0)
您好我跟着this link,它对我有用。
我试过这段代码
SoapObject item = new SoapObject(NAMESPACE, "shoppingCartProductEntity");
PropertyInfo pinfo = new PropertyInfo();
pinfo.setName("product_id");
pinfo.setValue(productId.get(deleteProductPosition));
pinfo.setType(String.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
pinfo.setName("sku");
pinfo.setValue(productSku.get(deleteProductPosition));
pinfo.setType(String.class);
item.addProperty(pinfo);
int productQty = Qty.get(deleteProductPosition);
pinfo = new PropertyInfo();
pinfo.setName("qty");
pinfo.setValue(productQty);
pinfo.setType(Double.class);
item.addProperty(pinfo);
pinfo = new PropertyInfo();
pinfo.setName("options");
pinfo.setValue(" ");
pinfo.setType(String[].class);
item.addProperty(pinfo);
SoapObject EntityArray = new SoapObject(NAMESPACE, "shoppingCartProductEntityArray");
EntityArray.addProperty("products",item);
SoapObject request = new SoapObject(NAMESPACE, "shoppingCartProductRemove");
request.addProperty("sessionId", sessionId);
request.addProperty("quoteId", 74);
request.addProperty("products",EntityArray);
env.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call("", env);
Object result = (Boolean) env.getResponse();
它为我工作。