pedidos
This commit is contained in:
@@ -363,6 +363,7 @@ export async function pushProductToWoo({ tenantId, wooProductId, categories, sel
|
||||
if (categories && Array.isArray(categories) && categories.length > 0) {
|
||||
// Primero obtener las categorías existentes en Woo para mapear nombres a IDs
|
||||
const existingCats = await fetchWooCategoriesByNames({ tenantId, names: categories });
|
||||
|
||||
if (existingCats.length > 0) {
|
||||
updatePayload.categories = existingCats.map(c => ({ id: c.id }));
|
||||
}
|
||||
@@ -424,8 +425,28 @@ async function fetchWooCategoriesByNames({ tenantId, names }) {
|
||||
page++;
|
||||
}
|
||||
|
||||
// Normalizar nombres - soportar formato jerárquico "Parent > Child"
|
||||
// Extraer TODAS las partes del path para asignar la jerarquía completa
|
||||
const normalizedNames = [];
|
||||
for (const n of names) {
|
||||
const full = String(n).toLowerCase().trim();
|
||||
// Si tiene formato jerárquico "Parent > Child > Grandchild", extraer cada parte
|
||||
if (full.includes(' > ')) {
|
||||
const parts = full.split(' > ').map(p => p.trim()).filter(Boolean);
|
||||
for (const part of parts) {
|
||||
if (!normalizedNames.includes(part)) {
|
||||
normalizedNames.push(part);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Categoría simple (sin jerarquía)
|
||||
if (!normalizedNames.includes(full)) {
|
||||
normalizedNames.push(full);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filtrar las que coinciden con los nombres buscados
|
||||
const normalizedNames = names.map(n => String(n).toLowerCase().trim());
|
||||
return allCategories.filter(c =>
|
||||
normalizedNames.includes(String(c.name).toLowerCase().trim()) ||
|
||||
normalizedNames.includes(String(c.slug).toLowerCase().trim())
|
||||
|
||||
Reference in New Issue
Block a user