moh Posted November 14, 2018 Share Posted November 14, 2018 hello developpers, i'm trying to add products to my Prestashop via php using webservices, i called the empty xml file, i've insert the resources product but i've got error when i'm trying to send the file to my shop (i've got an eroor 400) <?php define('DEBUG', false); define('PS_SHOP_PATH', 'http://myshop'); define('PS_WS_AUTH_KEY', 'UV******************4'); require_once('./PSWebServiceLibrary.php'); require_once'config_demo.php'; try { $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); } 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(); } $xml = $webService->get(array('url' => 'http://myshop/api/products?schema=synopsis')); $resources = $xml->product->children(); unset($resources->manufacturer_name); unset($resources->quantity); unset($resources->position_in_category); unset($resources->associations); unset ($resources->associations->categories->category); $resources->id = 1992; for($i = 0; $i < count($resources->name->language); $i++){ $resources->name->language[$i] = 'wortisbox'; $resources->link_rewrite->language[$i] = 'mon-produit-SAM'; } $resources->price = 285; //$resources->description="caisse enregistreuse de 10 pouces"; $resources->reference = "light"; echo "<pre>"; //var_dump($resources) ; echo "</pre>"; try { $opt = array( 'resource' => 'products' ); $opt[ 'postXml' ] = $xml->asXML(); $xml = $webService->add($opt); echo "product added"; } catch(PrestaShopWebserviceException $e) { $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(); echo "failed send"; } ?> can you help to resolve the problem please thank you ^__^ 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