u
This commit is contained in:
@@ -248,9 +248,9 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
|||||||
let productsXml = `<?xml version="1.0" encoding="UTF-8"?>
|
let productsXml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
|
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
|
||||||
<channel>
|
<channel>
|
||||||
<title>${config.descriptions.short}</title>
|
<title>${config.descriptions.de.short}</title>
|
||||||
<link>${baseUrl}</link>
|
<link>${baseUrl}</link>
|
||||||
<description>${config.descriptions.short}</description>
|
<description>${config.descriptions.de.short}</description>
|
||||||
<lastBuildDate>${currentDate}</lastBuildDate>
|
<lastBuildDate>${currentDate}</lastBuildDate>
|
||||||
<language>de-DE</language>`;
|
<language>de-DE</language>`;
|
||||||
|
|
||||||
@@ -308,6 +308,11 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
|||||||
|
|
||||||
// Add each product as an item
|
// Add each product as an item
|
||||||
allProductsData.forEach((product, index) => {
|
allProductsData.forEach((product, index) => {
|
||||||
|
|
||||||
|
console.log('DEBUG '+JSON.stringify(product, null, 2));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Skip products without essential data
|
// Skip products without essential data
|
||||||
if (!product || !product.seoName) {
|
if (!product || !product.seoName) {
|
||||||
@@ -360,15 +365,33 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
|||||||
const length = digits.length;
|
const length = digits.length;
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
|
|
||||||
for (let i = 0; i < length - 1; i++) {
|
if (length === 8) {
|
||||||
// Even/odd multiplier depends on GTIN length
|
// EAN-8: positions 0-6, check digit at 7
|
||||||
let multiplier = 1;
|
// Multipliers: 3,1,3,1,3,1,3 for positions 0-6
|
||||||
if (length === 8) {
|
for (let i = 0; i < 7; i++) {
|
||||||
multiplier = (i % 2 === 0) ? 3 : 1;
|
const multiplier = (i % 2 === 0) ? 3 : 1;
|
||||||
} else {
|
sum += digits[i] * multiplier;
|
||||||
multiplier = ((length - i) % 2 === 0) ? 3 : 1;
|
}
|
||||||
|
} 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;
|
const checkDigit = (10 - (sum % 10)) % 10;
|
||||||
return checkDigit === digits[length - 1];
|
return checkDigit === digits[length - 1];
|
||||||
@@ -397,8 +420,12 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
|||||||
return;
|
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
|
// 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) {
|
if (!originalDescription || originalDescription.length < 20) {
|
||||||
productsNeedingDescription.push({
|
productsNeedingDescription.push({
|
||||||
id: product.articleNumber || product.seoName,
|
id: product.articleNumber || product.seoName,
|
||||||
@@ -411,8 +438,8 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clean description for feed (remove HTML tags and limit length)
|
// Clean description for feed (remove HTML tags and limit length)
|
||||||
const rawDescription = cleanTextContent(product.description).substring(0, 500);
|
const feedDescription = cleanTextContent(productDescription).substring(0, 500);
|
||||||
const cleanDescription = escapeXml(rawDescription) || "Produktbeschreibung nicht verfügbar";
|
const cleanDescription = escapeXml(feedDescription) || "Produktbeschreibung nicht verfügbar";
|
||||||
|
|
||||||
// Clean product name
|
// Clean product name
|
||||||
const rawName = product.name || "Unnamed Product";
|
const rawName = product.name || "Unnamed Product";
|
||||||
|
|||||||
Reference in New Issue
Block a user