refactor: update category data fetching in Content component to utilize CategoryService directly and improve clarity in category management

This commit is contained in:
sebseb7
2025-07-24 11:55:08 +02:00
parent c1810b18b3
commit 7c78c6d85c

View File

@@ -301,15 +301,16 @@ class Content extends Component {
} }
processDataWithCategoryTree(response, categoryId) { processDataWithCategoryTree(response, categoryId) {
console.log("---------------processDataWithCategoryTree", response, categoryId);
// Get child categories from the cached category tree // Get child categories from the cached category tree
let childCategories = []; let childCategories = [];
try { try {
const categoryTreeCache = window.productCache && window.productCache['categoryTree_209']; const categoryTreeCache = window.categoryService.getSync(209);
if (categoryTreeCache && categoryTreeCache.categoryTree) { if (categoryTreeCache) {
// If categoryId is a string (SEO name), find by seoName, otherwise by ID // If categoryId is a string (SEO name), find by seoName, otherwise by ID
const targetCategory = typeof categoryId === 'string' const targetCategory = typeof categoryId === 'string'
? this.findCategoryBySeoName(categoryTreeCache.categoryTree, categoryId) ? this.findCategoryBySeoName(categoryTreeCache, categoryId)
: this.findCategoryById(categoryTreeCache.categoryTree, categoryId); : this.findCategoryById(categoryTreeCache, categoryId);
if (targetCategory && targetCategory.children) { if (targetCategory && targetCategory.children) {
childCategories = targetCategory.children; childCategories = targetCategory.children;
@@ -390,13 +391,10 @@ class Content extends Component {
const seoName = this.props.params.categoryId; const seoName = this.props.params.categoryId;
// Get the category tree from cache // Get the category tree from cache
const categoryTreeCache = window.productCache && window.productCache['categoryTree_209']; const categoryTreeCache = window.categoryService.getSync(209);
if (!categoryTreeCache || !categoryTreeCache.categoryTree) {
return null;
}
// Find the category by seoName // Find the category by seoName
const category = this.findCategoryBySeoName(categoryTreeCache.categoryTree, seoName); const category = this.findCategoryBySeoName(categoryTreeCache, seoName);
return category ? category.id : null; return category ? category.id : null;
} }
@@ -405,13 +403,10 @@ class Content extends Component {
if (!currentCategoryId) return null; if (!currentCategoryId) return null;
// Get the category tree from cache // Get the category tree from cache
const categoryTreeCache = window.productCache && window.productCache['categoryTree_209']; const categoryTreeCache = window.categoryService.getSync(209);
if (!categoryTreeCache || !categoryTreeCache.categoryTree) {
return null;
}
// Find the current category in the tree // Find the current category in the tree
const currentCategory = this.findCategoryById(categoryTreeCache.categoryTree, currentCategoryId); const currentCategory = this.findCategoryById(categoryTreeCache, currentCategoryId);
if (!currentCategory) { if (!currentCategory) {
return null; return null;
} }
@@ -422,7 +417,7 @@ class Content extends Component {
} }
// Find the parent category // Find the parent category
const parentCategory = this.findCategoryById(categoryTreeCache.categoryTree, currentCategory.parentId); const parentCategory = this.findCategoryById(categoryTreeCache, currentCategory.parentId);
if (!parentCategory) { if (!parentCategory) {
return null; return null;
} }
@@ -444,6 +439,8 @@ class Content extends Component {
const showCategoryBoxes = this.state.loaded && const showCategoryBoxes = this.state.loaded &&
this.state.unfilteredProducts.length === 0 && this.state.unfilteredProducts.length === 0 &&
this.state.childCategories.length > 0; this.state.childCategories.length > 0;
console.log("showCategoryBoxes", showCategoryBoxes, this.state.unfilteredProducts.length, this.state.childCategories.length);
return ( return (
@@ -576,7 +573,7 @@ class Content extends Component {
/> />
</Box> </Box>
{(this.getCurrentCategoryId() == 706 || this.getCurrentCategoryId() == 689) && {(this.props.params.categoryId == 'Stecklinge' || this.props.params.categoryId == 'Seeds') &&
<Box sx={{ display: { xs: 'none', sm: 'block' } }}> <Box sx={{ display: { xs: 'none', sm: 'block' } }}>
<Typography variant="h6" sx={{mt:3}}> <Typography variant="h6" sx={{mt:3}}>
{this.props.t ? this.props.t('navigation.otherCategories') : 'Andere Kategorien'} {this.props.t ? this.props.t('navigation.otherCategories') : 'Andere Kategorien'}