【问题标题】:Prestashop Update cart using WebservicesPrestashop 使用 Web 服务更新购物车
【发布时间】: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


【解决方案1】:

第一次没问题,但下次调用该代码时,使用“unset($xml->children()->children()->associations->cart_rows->cart_row);”我认为您删除了使用该行添加的先前 cart_row。

【讨论】:

  • 如果我删除此行,添加的第一个产品将被删除
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-12
  • 2021-12-31
  • 1970-01-01
  • 2014-08-29
  • 2022-10-25
  • 1970-01-01
  • 2021-03-17
相关资源
最近更新 更多