fixed category calculate

This commit is contained in:
vedatakd 2021-03-18 10:11:34 +03:00
parent 61a7bbcad6
commit 994c32fdeb
2 changed files with 45 additions and 40 deletions

View File

@ -24,6 +24,7 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
->orderBy('sort_order') ->orderBy('sort_order')
->get(); ->get();
} }
public function getSubCatById($id) public function getSubCatById($id)
{ {
$cats = $this->model->newQuery() $cats = $this->model->newQuery()
@ -108,7 +109,8 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
public function getLevelById($id) public function getLevelById($id)
{ {
return count($this->getParentCategoryById($id)); $parents = $this->getParentCategoryById($id);
return (is_array($parents)) ? count($parents) : null;
} }
public function getCategoriesByName($keyword) public function getCategoriesByName($keyword)

View File

@ -44,6 +44,8 @@ class CalculateCategoryLevel
$level = $categoryRepository->getLevelById($category_id); $level = $categoryRepository->getLevelById($category_id);
if($level)
{
DB::table('cats_category')->where('id', $category_id) DB::table('cats_category')->where('id', $category_id)
->update(array( ->update(array(
'level' => $level, 'level' => $level,
@ -51,3 +53,4 @@ class CalculateCategoryLevel
)); ));
} }
} }
}