nikksan nikksan - 4 days ago 9
PHP Question

Prestashop Webservice to add simple product

I am writing a script that will add products through the webservice.
I`m having some dificulties for a couple of hours so I seek for help.
This is what I have now.

require_once("config.php");
require_once("PSWebServiceLibrary.php");

try {

$webService = new PrestaShopWebservice(SITE_URL, WEBSERVICE_AUTH_KEY, DEBUG_MODE);
$xml = $webService->get(array('url' => SITE_URL.'/api/products?schema=synopsis'));
$product = $xml->children()->children();
$product->price = 99;
$product->wholesale_price = 89;
$product->active = '1';
$product->on_sale = 0;
$product->show_price = 1;
$product->available_for_order = 1;

$product->name->language[0][0] = "Produit webservice";
$product->name->language[0][0]['id'] = 1;
$product->name->language[0][0]['xlink:href'] = SITE_URL . '/api/languages/' . 1;

$product->description->language[0][0] = "Description produit webservice";
$product->description->language[0][0]['id'] = 1;
$product->description->language[0][0]['xlink:href'] = SITE_URL . '/api/languages/' . 1;

$product->description_short->language[0][0] = "Descr. courte";
$product->description_short->language[0][0]['id'] = 1;
$product->description_short->language[0][0]['xlink:href'] = SITE_URL . '/api/languages/' . 1;
$product->reference = "ref_product_webservice";

$product->depends_on_stock = 0;

$category_id = 3;
$product->associations->categories->addChild('category')->addChild('id', $category_id);
$product->id_category_default = $category_id;

//
$opt = array('resource' => 'products');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
}
catch (PrestaShopWebserviceException $ex) {
echo "Error:<br>";
echo $ex->getMessage();
exit(1);
}


I have my webservice all set up , but I keep getting this error :


This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error.


Please tell me what I am doing wrong.

Answer

Changed the schema to blank , and now it`s working. The initial error was:

Attribute "href" bound to namespace

Comments