protected function sortCategoriesTree(array $categoriesOrder, $parentCategory = null)
{
$counter = 0;
foreach ($categoriesOrder as $categoryInfo) {
$category = $this->categoryRepository->findOneBy(['id' => $categoryInfo['id']]);
if (is_null($category)) {
return false;
}
$category->setPosition($counter);
if ($parentCategory) {
$category->setPosition($counter);
$category->setRoot(false);
$category->setParent($parentCategory);
} else {
$category->setPosition($counter);
$category->setRoot(true);
$category->setParent(null);
}
++$counter;
if (isset($categoryInfo['subtree']) && !$this->sortCategoriesTree($categoryInfo['subtree'], $category)) {
return false;
}
}
return true;
}