【发布时间】:2015-04-28 09:17:05
【问题描述】:
我在我的 android 应用程序中使用 prestashop API 网络服务来创建购物车并根据用户的需要对其进行修改。
我对创建购物车没有任何问题,但是当我添加新产品时,旧产品会被删除。
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();}
【问题讨论】:
-
你好!我从一个问得很好的问题中删除了一些不必要的文本。请理解“谢谢”或“请帮助”与问题没有直接关系。祝你好运!
标签: php android web-services prestashop