Jump to content

Webservice add Products


Recommended Posts

Hi,

i read the whole CRUD tutorial thing, fair to say it's incomplete !

the issue is that i can't add products using the webservice with POST, i get the error HTTP 400 bad request ...

here is the code :

 

require_once('PSWebserviceLibrary.php');

 

$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

 

$xml_product = $webService->get(array('resource' => 'products?schema=synopsis'));

$resources_product = $xml_product->children()->children();

 

// champs requis

$resources_product->quantity = 0;

$resources_product->price = 1;

$resources_product->out_of_stock = 2;

$resources_product->name->language[0][0] = 'test';

$resources_product->link_rewrite->language[0][0] = 'test';

 

// par exemple pour vider les associations aux categories

unset($resources_product->associations->categories->category);

 

// associer a une categorie (id = 1)

$resources_product->associations->categories->addChild('category')->addChild('id', 1);

 

$xml_product = $webService->add(array('resource' => 'products', 'postXml' => $xml_product->asXML()));

 

 

thanks

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

You have to display the prestashop errors to know what happened.

Go to the conf file and set the display error var to true.

 

Some of the errors or due to some fields in your XML that don't have to be in add or update items. Even if there are in a the blank or synopsis xml.

 

Regards

Link to comment
Share on other sites

  • 8 months later...
×
×
  • Create New...