Hi guys i'm trying to add a new product via web services using the PSWebServiceLibrary, i tried to read other posts in this forum but i have problems.
That's my code:
function AddProduct($root_path, $authentication_key, $id, $name, $desc, $cat, $qta, $price){
try{
$webService = CreateWebServer($root_path,$authentication_key);
$xml = $webService->get(array('resource' => 'products?schema=synopsis'));
}catch(PrestashopWebserviceException $ex){
echo $ex->getMessage();
return -1;
}
$resources = $xml->children()->children();
unset($resources->position_in_category);
unset($resources->manufacturer_name);
$resources->price = floatval($price);
$resources->quantity = intval($qta);
$resources->link_rewrite->language[0][0] = str_replace(' ','-',$name);
$resources->name->language[0][0] = $name;
$resources->description->language[0][0] = $desc;
$node= dom_import_simplexml($resources->description->language[0][0]);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($desc));
$resources->associations = '';
//echo $xml->asXML();
try{
$opt = array('resource' => 'products');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
}
catch(PrestaShopWebserviceException $ex)
{
echo $ex->getMessage();
}
return 0;
}
When I run this funcion it gives me error:
I think there's a sort of problem with the "required=true" parameters, but i don't know what to do.
Thanks.