Hi zusammen,
Ich habe einen CLI Importer geschrieben, der Kategorien aus einem XML ausliest und anleg bzw. aktualisiert. Das funktioniert gut, solange ich nicht explizit eine ID für die Kategorie vorgebe. Ist eine Kategorie ID angegeben, legt Shopware die ersten 5 Kategorien problemlos an um danach ich eine Exception zu laufen:
Maximum function nesting level of ‚256‘ reached, aborting! in /engine/Shopware/Components/Model/CategoryDenormalization.php on line 77
Selbst wenn ich das nesting level auf 1024 erhöhe, kommt es zum selben Fehler - dauert halt nur länger.
Hier die Methode, die ich zum Importieren einsetze:
/**
* @param $xml
* Import the product categories from SPM
*/
public function importCategoriesSpm($xml)
{
// Get the ressource
$categoryResource = \Shopware\Components\Api\Manager::getResource('category');
// Iterate over all post nodes in XML
foreach ($xml->category as $category):
// Find out the attributes
$attributes = $category->attributes();
$categoryId = $attributes['id'];
// @TODO: Skipping this item if the category ID = 3 (shopware default)
if ($categoryId==3) continue;
// Map the parent ID
$parentId = 3;
if($attributes['parent_id'] != '0'):
$parentId = $attributes['parent_id'];
endif;
$categoryData = array(
'parentId' => 3,
'name' => $category->name,
'cmsHeadline' => $category->name,
'cmsText' => $category->subtitle,
'metaDescription' => $category->subtitle,
'active' => true,
'showFilterGroup' => true
);
try {
$category = $categoryResource->update($categoryId, $categoryData);
$this->log('success', 'Category "'.$category->getName().'" successfully updated.');
} catch (\Shopware\Components\Api\Exception\NotFoundException $e) {
$categoryData['id'] = (int) $categoryId;
$category = $categoryResource->create($categoryData);
$this->log('success', 'Category "'.$category->getName().'" successfully imported.');
}
endforeach;
}
Sobald ich die Category ID nicht setze, läuft der Importer wunderbar. Allerdings würde ich gerne die ID selbst bestimmen um mir das einführen eine Referenz-ID zu ersparen.
Danke für Eure Inputs vorweg,
LG