visible and count
This commit is contained in:
@@ -63,10 +63,10 @@ export class SubcategoriesComponent implements OnInit, OnDestroy {
|
||||
|
||||
// Check for nested subcategories from API response (backOffice format)
|
||||
const nested = parent?.subcategories || [];
|
||||
const visibleNested = nested.filter(s => s.visible !== false);
|
||||
const visibleNested = nested.filter(s => this.isDisplayableNestedSubcategory(s));
|
||||
|
||||
// Also check flat legacy subcategories
|
||||
const flatSubs = cats.filter(c => c.parentID === parentID);
|
||||
const flatSubs = cats.filter(c => c.parentID === parentID && this.isDisplayableFlatSubcategory(c));
|
||||
|
||||
if (visibleNested.length > 0) {
|
||||
// Use nested subcategories from API
|
||||
@@ -110,6 +110,20 @@ export class SubcategoriesComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
private isDisplayableFlatSubcategory(category: Category): boolean {
|
||||
return category.visible !== false
|
||||
&& ((category.itemCount ?? 0) > 0 || (category.subcategories?.length ?? 0) > 0);
|
||||
}
|
||||
|
||||
private isDisplayableNestedSubcategory(subcategory: Subcategory): boolean {
|
||||
return subcategory.visible !== false
|
||||
&& (
|
||||
(subcategory.itemCount ?? 0) > 0
|
||||
|| subcategory.hasItems === true
|
||||
|| (subcategory.subcategories?.length ?? 0) > 0
|
||||
);
|
||||
}
|
||||
|
||||
hasSubcategories(): boolean {
|
||||
return this.subcategories().length > 0 || this.nestedSubcategories().length > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user