u
This commit is contained in:
@@ -259,10 +259,12 @@ class Content extends Component {
|
|||||||
|
|
||||||
|
|
||||||
fetchCategoryData(categoryId) {
|
fetchCategoryData(categoryId) {
|
||||||
// Check if we have the category tree data in window.productCache
|
// Simply check if we have any category tree data in window.productCache
|
||||||
const hasCategoryTree = window.productCache &&
|
const hasCategoryTree = window.productCache &&
|
||||||
window.productCache["categoryTree_209"] &&
|
Object.keys(window.productCache).some(key =>
|
||||||
window.productCache["categoryTree_209"].categoryTree;
|
key.startsWith("categoryTree_209") &&
|
||||||
|
window.productCache[key] &&
|
||||||
|
window.productCache[key].categoryTree);
|
||||||
|
|
||||||
// Check for specific category data in cache
|
// Check for specific category data in cache
|
||||||
const cachedData = getCachedCategoryData(categoryId);
|
const cachedData = getCachedCategoryData(categoryId);
|
||||||
@@ -412,15 +414,27 @@ class Content extends Component {
|
|||||||
|
|
||||||
// Helper function to get category name from tree
|
// Helper function to get category name from tree
|
||||||
getCategoryNameFromTree = (categoryId) => {
|
getCategoryNameFromTree = (categoryId) => {
|
||||||
if (!window.productCache || !window.productCache["categoryTree_209"] ||
|
if (!window.productCache) {
|
||||||
!window.productCache["categoryTree_209"].categoryTree) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the first available category tree
|
||||||
|
const categoryTreeKey = Object.keys(window.productCache).find(key =>
|
||||||
|
key.startsWith("categoryTree_209") &&
|
||||||
|
window.productCache[key] &&
|
||||||
|
window.productCache[key].categoryTree
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!categoryTreeKey) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const categoryTree = window.productCache[categoryTreeKey].categoryTree;
|
||||||
|
|
||||||
// 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 category = typeof categoryId === 'string'
|
const category = typeof categoryId === 'string'
|
||||||
? this.findCategoryBySeoName(window.productCache["categoryTree_209"].categoryTree, categoryId)
|
? this.findCategoryBySeoName(categoryTree, categoryId)
|
||||||
: this.findCategoryById(window.productCache["categoryTree_209"].categoryTree, categoryId);
|
: this.findCategoryById(categoryTree, categoryId);
|
||||||
|
|
||||||
return category ? category.name : null;
|
return category ? category.name : null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user