我已经通过 web 服务创建了一个简单的添加产品到 prestashop,但是当我尝试将它添加到数据库时,我只看到一个错误'Bad parameters given'。我的代码有什么问题?我怎样才能找到一个类别是否已经存在于网络服务中?
$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);
}
}
}