// MARK: - Variant Attribute & Value Helpers // #region Variant Attribute & Value Helpers /** * Normalizes common variant attribute names and typos. * * @param {string} name * @returns {string} */ export function normalizeAttributeName(name) { const clean = (name || '').trim(); if (!clean) return 'Variante'; const lower = clean.toLowerCase(); if (lower === 'menge' || lower === 'mange' || lower === 'meneg') return 'Menge'; if (lower === 'farbe') return 'Farbe'; if (lower === 'größe' || lower === 'grosse') return 'Größe'; if (lower === 'sorte') return 'Sorte'; if (lower === 'geschmack') return 'Geschmack'; if (lower === 'typ') return 'Typ'; if (lower === 'stück' || lower === 'stueck') return 'Stück'; if (lower === 'ausführung' || lower === 'ausfuehrung') return 'Ausführung'; if (lower === 'motiv') return 'Motiv'; return clean.charAt(0).toUpperCase() + clean.slice(1); } /** * Fallback variant value extraction if child has no explicit attribute value. * * @param {string} parentName * @param {string} childName * @param {string} childSku * @param {string} parentSku * @returns {string} */ export function extractVariantValue(parentName, childName, childSku, parentSku) { let pName = (parentName || '').replace(/[©®™]/g, '').trim(); let cName = (childName || '').replace(/[©®™]/g, '').trim(); if (pName && cName) { if (cName.toLowerCase().startsWith(pName.toLowerCase())) { let val = cName.slice(pName.length).trim().replace(/^[-–—:/,\s]+/, '').trim(); if (val) return val; } } if (parentSku && childSku && childSku.startsWith(parentSku)) { let suffix = childSku.slice(parentSku.length).trim().replace(/^[-_]+/, '').trim(); if (suffix) return suffix; } if (cName && cName !== pName) return cName; return childSku || 'Standard'; } // #endregion