IeM Posted July 21, 2013 Share Posted July 21, 2013 (edited) Hi, As a customer joins another site ( , I need a script to call the Prestashop webservice from that site to update that user's customer id_default_group value in site A. We already know the user's Prestashop Id and what the new group Id should be. So far I have the following (error checking not included): require_once( './PSWebServiceLibrary.php'); $webService = new PrestaShopWebservice($siteUrl, $key, false); $opt = array('resource'=>'customers','display'=> '[id_default_group]','filter[id]' => $id); $xml = $webService->get($opt); $resources = $xml->children()->children(); //?????????? The correct element location is $xml->children()->children()->children; I do not want to view the details or manually update them. The script needs to take the known id_customer and new id_default_group value and use them to automatically update Prestashop (Site A from . I do not know how to update the id_default_group value in the returned data and create/format the data to send back. This almost works: $xml->customers->customer->id_default_group = 4; $resources = $xml->children()->children()->children(); As it sets the correct child element but when it is sent back the header response is "HTTP/1.1 400 Bad Request". Thanks for your assistance. Edited August 4, 2013 by IeM (see edit history) Link to comment Share on other sites More sharing options...
IeM Posted August 5, 2013 Author Share Posted August 5, 2013 Update I have a working web service update, though, there is an important improvement that needs to be made. In the script below all of the details for a user are retrieved, the "id_default_group" is modified and the customer record is updated. The script needs to be modified so that it only retrieves the customer's "id_default_group" and not all of the details, modifies it's value, then updates the record. I tried restricting the data using "display" => '[id_default_group]' but I could not get it right. Hopefully someone can correct this script, thanks. <?php // Call webservice if(isset($_SESSION['iemIdCustomer'])){ define('DEBUG', false); define('PS_SHOP_PATH', 'http://www.domain.com/'); define('PS_WS_AUTH_KEY', 'xxxxxxxxxxxx'); require_once( '../PSWebServiceLibrary.php'); // Get the customer's id_default_group try { $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $opt = array('resource' => 'customers'); $opt['id'] = $_SESSION["iemIdCustomer"]; $xml = $webService->get($opt); // Get the elements from children of customer $resources = $xml->children()->children()->children(); } 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'; } // Update the data and send it to the web service // Update XML with new value $xml->children()->children()->id_default_group = 4; // And call the web service try { $opt = array('resource' => 'customers'); $opt['putXml'] = $xml->asXML(); $opt['id'] = $_SESSION['iemIdCustomer']; $xml = $webService->edit($opt); echo "Successfully updated."; } 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<br />'.$ex->getMessage(); } } ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now