diff --git a/innopacks/common/src/Repositories/ProductRepo.php b/innopacks/common/src/Repositories/ProductRepo.php index fbc9ddd08..72dd0d7e2 100644 --- a/innopacks/common/src/Repositories/ProductRepo.php +++ b/innopacks/common/src/Repositories/ProductRepo.php @@ -941,6 +941,27 @@ public function getBundleItems(Product $product): Collection */ public static function getCategoryOptions(): array { - return CategoryRepo::formatCategoriesForCascader(Category::tree()); + // Get only active categories and build tree structure + $activeCategories = Category::where('active', true) + ->with(['translation', 'children.translation']) + ->orderBy('position') + ->get(); + + // Build tree structure manually since we need to filter by active status + $tree = collect(); + $itemsById = $activeCategories->keyBy('id'); + + foreach ($activeCategories as $category) { + if ($category->parent_id && isset($itemsById[$category->parent_id])) { + if (!isset($itemsById[$category->parent_id]->children)) { + $itemsById[$category->parent_id]->children = collect(); + } + $itemsById[$category->parent_id]->children->push($category); + } else { + $tree->push($category); + } + } + + return CategoryRepo::formatCategoriesForCascader($tree); } }