fireridlle Posted April 8, 2014 Share Posted April 8, 2014 (edited) if (count($params) > 0) { // Here we have XML before update, lets update XML foreach ($resources as $nodeKey => $node) { $element = $resources->$nodeKey; if((string)$nodeKey == 'associations') { // echo '----------------------------------------</br>'; foreach ($node as $childKey => $value) { if($value->children()->category) { $value->children()->category->children()->id[0] = 8; } // echo '<tr><th>'.$childKey.'</th></br>'; // echo '<tr><th>'.var_dump($value->children()[0]).'</th></br>'; } // echo '----------------------------------------</br>'; } else { if($element->children()->language) { $resources->$nodeKey->children()->language[0][0] = $params[$nodeKey]; } else { $resources->$nodeKey = $params[$nodeKey]; } } } try { { $resources = $webService->add(array('resource' => 'products', 'postXml' => $xml->asXML())); $resources = $resources->children()->children(); foreach ($resources as $key => $value) { if($key == 'id') { //////////////////////////////////// $id_product = $value; $url = $params['picture']; $shops = Shop::getShops(true, null, true); $image = new Image(); $image->id_product = $id_product; $image->position = Image::getHighestPosition($id_product) + 1; $image->cover = true; // or false; //echo 'try </br>'; if (($image->validateFields(false, true)) === true && ($image->validateFieldsLang(false, true)) === true && $image->add()) { //echo 'nice 1 </br>'; $image->associateTo($shops); if (!AdminImportController::copyImg($id_product, $image->id, $url, 'products', false)) { //echo 'nice 3 </br>'; $image->delete(); } } //////////////////////////////////// return (string)$value; } } } } catch (PrestaShopWebserviceException $ex) { // Here we are dealing with errors $trace = $ex->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 2<br />'.$ex->getMessage(); echo '<script type="text/javascript">alert("Error");</script>'; } } } I got exception: Other error 2<br />This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request Edited April 8, 2014 by fireridlle (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts