fix: validate product weight before XML generation and update weight handling
This commit is contained in:
@@ -386,6 +386,18 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if product has weight data - validate BEFORE building XML
|
||||
if (!product.weight || isNaN(product.weight)) {
|
||||
// Track products without weight
|
||||
productsNeedingWeight.push({
|
||||
id: product.articleNumber || product.seoName,
|
||||
name: product.name || 'Unnamed',
|
||||
url: `/Artikel/${product.seoName}`
|
||||
});
|
||||
skippedCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if description is missing or too short (less than 20 characters) - skip if insufficient
|
||||
const originalDescription = product.description ? cleanTextContent(product.description) : '';
|
||||
if (!originalDescription || originalDescription.length < 20) {
|
||||
@@ -460,7 +472,7 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
||||
const googleCategory = getGoogleProductCategory(categoryId);
|
||||
const escapedGoogleCategory = escapeXml(googleCategory);
|
||||
|
||||
// Build item XML with proper formatting
|
||||
// Build item XML with proper formatting (all validation passed, safe to write XML)
|
||||
productsXml += `
|
||||
<item>
|
||||
<g:id>${productId}</g:id>
|
||||
@@ -486,21 +498,11 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
||||
<g:gtin>${gtin}</g:gtin>`;
|
||||
}
|
||||
|
||||
// Check if product has weight data - skip if missing
|
||||
if (!product.weight || isNaN(product.weight)) {
|
||||
// Track products without weight
|
||||
productsNeedingWeight.push({
|
||||
id: product.articleNumber || product.seoName,
|
||||
name: product.name || 'Unnamed',
|
||||
url: `/Artikel/${product.seoName}`
|
||||
});
|
||||
skippedCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Add weight (we know it exists at this point)
|
||||
// Add weight (we know it exists at this point since we validated it earlier)
|
||||
// Convert from kg to grams (multiply by 1000)
|
||||
const weightInGrams = parseFloat(product.weight) * 1000;
|
||||
productsXml += `
|
||||
<g:shipping_weight>${parseFloat(product.weight).toFixed(2)} g</g:shipping_weight>`;
|
||||
<g:shipping_weight>${weightInGrams.toFixed(2)} g</g:shipping_weight>`;
|
||||
|
||||
// Add unit pricing data (required by German law for many products)
|
||||
const unitPricingData = determineUnitPricingData(product);
|
||||
|
||||
@@ -78,9 +78,9 @@ const MainPageLayout = () => {
|
||||
};
|
||||
|
||||
const allTitles = {
|
||||
home: t('titles.home'),
|
||||
aktionen: t('titles.aktionen'),
|
||||
filiale: t('titles.filiale')
|
||||
home: t('titles.filiale'),
|
||||
aktionen: t('titles.home'),
|
||||
filiale: t('titles.aktionen')
|
||||
};
|
||||
|
||||
// Define all content boxes for layered rendering
|
||||
|
||||
Reference in New Issue
Block a user