我在我的Android应用程序中使用prestashop API Web服务来创建购物车并根据需要从用户修改它。
我对购物车的创建没有任何问题,但是当我添加新产品时,旧产品会被删除。
try{
$webService = new PrestaShopWebservice($serverUrl, $serverApiKey, true);
$opt = array('resource' => 'carts');
$opt['id'] = $idCart;
$xml = $webService->get($opt);
$resources = $xml->children()->children()->children();
unset($xml->children()->children()->associations->cart_rows->cart_row);
$xml->children()->children()->associations->cart_rows->addChild('cart_row')->addChild('id_product', $idProduct);
$xml->children()->children()->associations->cart_rows->cart_row->addChild('quantity', $qty);
$opt = array('resource' => 'carts');
$opt['putXml'] = $xml->asXML();
$opt['id'] = $idCart; // 17
$xml = $webService->edit($opt);}
catch(PrestaShopWebserviceException $e){
// Here we are dealing with errors
$trace = $e->getTrace();if ($trace[0]['args'][0] == 404) echo 'Bad ID'; else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error'.$e->getMessage();}
答案 0 :(得分:0)
第一次没问题,但是下次您拨打该代码时,使用"取消设置($ xml-> children() - > children() - > association- > cart_rows-> cart_row);"我想你删除了之前用该行添加的cart_row。