Use new categories correctly in existing components and handle category names with commas
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user