fix: validate product weight before XML generation and update weight handling

This commit is contained in:
sebseb7
2025-07-19 23:04:52 +02:00
parent f2ee641bfd
commit 349b004627
2 changed files with 20 additions and 18 deletions

View File

@@ -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);

View File

@@ -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