Use new categories correctly in existing components and handle category names with commas

This commit is contained in:
2025-01-11 01:25:52 -05:00
parent 0bc86a3fee
commit d805e49449
9 changed files with 556 additions and 53 deletions

View File

@@ -83,10 +83,36 @@ async function handleCategories(connection, productId, categoriesStr) {
return;
}
// Split categories and clean them
const categories = categoriesStr.split(',')
// Special cases that should not be split
const specialCategories = [
'Paint, Dyes & Chalk',
'Fabric Paint, Markers, and Dye',
'Crystals, Gems & Rhinestones',
'Pens, Pencils & Markers'
];
// Split categories and clean them, preserving special cases
const categories = [];
let remainingStr = categoriesStr;
// First check for special categories
for (const special of specialCategories) {
if (remainingStr.includes(special)) {
categories.push(special);
// Remove the special category from the string
remainingStr = remainingStr.replace(special, '');
}
}
// Then process any remaining regular categories
remainingStr.split(',')
.map(cat => cat.trim())
.filter(cat => cat.length > 0);
.filter(cat => cat.length > 0)
.forEach(cat => {
if (!categories.includes(cat)) {
categories.push(cat);
}
});
// Remove existing category relationships for this product
await connection.query(