Fusef Posted December 9, 2017 Share Posted December 9, 2017 (edited) Hi, and thanks and appreciate any help, debug report attached.: My error: testyOther errorThis call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request. Quote <?php define('DEBUG', false); // Debug mode define('PS_SHOP_PATH', 'Taken out'); // Root path of your PrestaShop store http://www.myshop.com/ define('PS_WS_AUTH_KEY', 'Taken out); // Auth key (Get it in your Back Office)ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ require_once('./PSWebServiceLibrary.php'); try { $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $opt = array('resource' => 'products'); if (isset($_GET['id'])) $opt['id'] = $_GET['id']; $xml = $webService->get($opt); // Here we get the elements from children of customer markup which is children of prestashop root markup $resources = $xml->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<br />'.$e->getMessage(); } if (isset($_GET['id']) && isset($_POST['id'])) // Here we check id cause in every resource there's an id { // Here we have XML before update, lets update XML with new values foreach ($resources as $nodeKey => $node) { $resources->$nodeKey = $_POST[$nodeKey]; } // And call the web service try { $opt = array('resource' => 'products'); $opt['id'] = $_GET[ 'id' ]; $opt['putXml'] = $xml->children()->asXML(); $xml =$webService->edit($opt) ; // if WebService don't throw an exception the action worked well and we don't show the following message echo "Successfully updated."; } catch (PrestaShopWebserviceException $ex) { // Here we are dealing with errors echo "testy"; $trace = $ex->getTrace(); if ($trace[1]['args'][0] == 404) echo 'Bad ID'; else if ($trace[0]['args'][0] == 401) echo 'Bad auth key'; else echo 'Other error<br />'.$ex->getMessage(); } } if (isset($_GET['id'])) echo '<form method="POST" action="?id='.$_GET['id'].'">'; ?> <br> <table class="table table-striped table-bordered table-hover" data-provide="datatable" data-info="true" > <?php if(isset($resources)) { if(!isset($_GET['id'])) { ?> <thead> <tr> <th data-filterable="true">Product's Id</th> <th data-filterable="true">Manufacturer</th> <th data-filterable="true">Supplier</th> <th data-filterable="true">Price</th> <th data-filterable="false" class="hidden-xs hidden-sm">Update</th> </tr> </thead> <tbody> <?php foreach ($resources as $resource ) { $opt['id'] = $resource->attributes(); $xml = $webService->get($opt); $r = $xml->children()->children(); //print_r($r2); //print_r($r); echo '<tr>'; echo '<td>'.$r->id.'</td>'; echo '<td>'.$r2->name.'</td>'; echo '<td>'.$r3->name.'</td>'; echo '<td>'.$r->price.'</td>'; echo '<td><a href="?id='.$resource->attributes().'">Update</a></td>'; echo '</tr>'; } } else { foreach ($resources as $key => $resource) { echo '<tr>'; echo '<th>'.$key.'</th><td>'; echo '<input type="text" id="name" name="'.$key.'" value="'.$resource.'" class="form-control" data-required="true" >'; echo '</td></tr>'; } } } ?> </tbody> </table> <?php if (isset($_GET['id'])) echo '<input type="submit" class="btn btn-success" value="Update"></form>'; ?> </div> <!-- /.table-responsive --> </div> <!-- /.portlet-content --> </div> <!-- /.portlet --> </div> <!-- /.col --> </div> <!-- /.row --> I have searched every corner of the web and tried everything. I am sure its something simple I can not see. So frustrating. Thanks. debugreport.txt Edited December 9, 2017 by Fusef (see edit history) Link to comment Share on other sites More sharing options...
El Severo Posted April 9, 2019 Share Posted April 9, 2019 Any feedback related to your issue? 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