public function saveDetail() { $params =
$this->
Request()->
getParams();
$categoryId =
(int) ($params['id'
] ?? 0
);
$repo =
$this->em->
getRepository(Category::
class);
if (empty($categoryId)) { $categoryModel =
new Category();
$this->em->
persist($categoryModel);
// Find parent for newly created category
$params['parentId'
] =
isset($params['parentId'
]) &&
is_numeric($params['parentId'
]) ?
(int) $params['parentId'
] : 1;
/** @var Category $parentCategory */
$parentCategory =
$repo->
find($params['parentId'
]);
$categoryModel->
setParent($parentCategory);
// If Leaf-Category gets child category move all assignments to new child category
if ($parentCategory->
getChildren()->
count() === 0 &&
$parentCategory->
getArticles()->
count() > 0
) { /** @var Article $product */