diff --git a/prerender/seo/feeds.cjs b/prerender/seo/feeds.cjs index 3192633..49567f4 100644 --- a/prerender/seo/feeds.cjs +++ b/prerender/seo/feeds.cjs @@ -248,9 +248,9 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => { let productsXml = ` - ${config.descriptions.short} + ${config.descriptions.de.short} ${baseUrl} - ${config.descriptions.short} + ${config.descriptions.de.short} ${currentDate} de-DE`; @@ -308,6 +308,11 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => { // Add each product as an item allProductsData.forEach((product, index) => { + + console.log('DEBUG '+JSON.stringify(product, null, 2)); + + + try { // Skip products without essential data if (!product || !product.seoName) { @@ -360,15 +365,33 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => { const length = digits.length; let sum = 0; - for (let i = 0; i < length - 1; i++) { - // Even/odd multiplier depends on GTIN length - let multiplier = 1; - if (length === 8) { - multiplier = (i % 2 === 0) ? 3 : 1; - } else { - multiplier = ((length - i) % 2 === 0) ? 3 : 1; + if (length === 8) { + // EAN-8: positions 0-6, check digit at 7 + // Multipliers: 3,1,3,1,3,1,3 for positions 0-6 + for (let i = 0; i < 7; i++) { + const multiplier = (i % 2 === 0) ? 3 : 1; + sum += digits[i] * multiplier; + } + } else if (length === 12) { + // UPC-A: positions 0-10, check digit at 11 + // Multipliers: 3,1,3,1,3,1,3,1,3,1,3 for positions 0-10 + for (let i = 0; i < 11; i++) { + const multiplier = (i % 2 === 0) ? 3 : 1; + sum += digits[i] * multiplier; + } + } else if (length === 13) { + // EAN-13: positions 0-11, check digit at 12 + // Multipliers: 1,3,1,3,1,3,1,3,1,3,1,3 for positions 0-11 + for (let i = 0; i < 12; i++) { + const multiplier = (i % 2 === 0) ? 1 : 3; + sum += digits[i] * multiplier; + } + } else if (length === 14) { + // EAN-14: similar to EAN-13 but 14 digits + for (let i = 0; i < 13; i++) { + const multiplier = (i % 2 === 0) ? 1 : 3; + sum += digits[i] * multiplier; } - sum += digits[i] * multiplier; } const checkDigit = (10 - (sum % 10)) % 10; return checkDigit === digits[length - 1]; @@ -397,8 +420,12 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => { return; } + // Get description from the appropriate field + // TODO: Identify the correct field name used by the product data + const productDescription = product.shortDescription || product.longDescription || product.description || ''; + // Check if description is missing or too short (less than 20 characters) - skip if insufficient - const originalDescription = product.description ? cleanTextContent(product.description) : ''; + const originalDescription = productDescription ? cleanTextContent(productDescription) : ''; if (!originalDescription || originalDescription.length < 20) { productsNeedingDescription.push({ id: product.articleNumber || product.seoName, @@ -411,8 +438,8 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => { } // Clean description for feed (remove HTML tags and limit length) - const rawDescription = cleanTextContent(product.description).substring(0, 500); - const cleanDescription = escapeXml(rawDescription) || "Produktbeschreibung nicht verfügbar"; + const feedDescription = cleanTextContent(productDescription).substring(0, 500); + const cleanDescription = escapeXml(feedDescription) || "Produktbeschreibung nicht verfügbar"; // Clean product name const rawName = product.name || "Unnamed Product";