I have createed a simple add product to prestashop via webservice but when I try to add this to the DB I see only an error 'Bad parameters given'. What is wrong with my code? And how can I find if a category already exist with webservice?
$reader = new XMLReader;
$reader->open($filename); // open an large xml with products and it should add this to db prestashop via webservice
$xml = $webService->get(array('url' => $shopUrl.'/api/products?schema=blank'));
$resources = $xml->children()->children();
foreach ($resources as $resource) {
while ($reader->read()) {
if($reader->nodeType == XMLReader::ELEMENT) {
$name = $reader->name;
}
if($reader->nodeType == XMLReader::TEXT || $reader->nodeType == XMLReader::CDATA){
switch ($name) {
case 'id':
if ($reader->value != '0')
$resource->id = $reader->value;
break;
case 'ilosc':
$resource->quantity = $reader->value;
break;
case 'cena_netto':
$resource->price = $reader->value;
break;
case 'opis':
$resource->description = $reader->value;
break;
case 'waga':
$resource->weight = $reader->value;
break;
case 'kod_kreskowy':
$resource->ean13 = $reader->value;
break;
}
}
if($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'produkt'){
$reader->next();
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
}
}
}