Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion innopacks/common/src/Repositories/ProductRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}