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; 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 // Check if description is missing or too short (less than 20 characters) - skip if insufficient
const originalDescription = product.description ? cleanTextContent(product.description) : ''; const originalDescription = product.description ? cleanTextContent(product.description) : '';
if (!originalDescription || originalDescription.length < 20) { if (!originalDescription || originalDescription.length < 20) {
@@ -460,7 +472,7 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
const googleCategory = getGoogleProductCategory(categoryId); const googleCategory = getGoogleProductCategory(categoryId);
const escapedGoogleCategory = escapeXml(googleCategory); const escapedGoogleCategory = escapeXml(googleCategory);
// Build item XML with proper formatting // Build item XML with proper formatting (all validation passed, safe to write XML)
productsXml += ` productsXml += `
<item> <item>
<g:id>${productId}</g:id> <g:id>${productId}</g:id>
@@ -486,21 +498,11 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
<g:gtin>${gtin}</g:gtin>`; <g:gtin>${gtin}</g:gtin>`;
} }
// Check if product has weight data - skip if missing // Add weight (we know it exists at this point since we validated it earlier)
if (!product.weight || isNaN(product.weight)) { // Convert from kg to grams (multiply by 1000)
// Track products without weight const weightInGrams = parseFloat(product.weight) * 1000;
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)
productsXml += ` 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) // Add unit pricing data (required by German law for many products)
const unitPricingData = determineUnitPricingData(product); const unitPricingData = determineUnitPricingData(product);

View File

@@ -78,9 +78,9 @@ const MainPageLayout = () => {
}; };
const allTitles = { const allTitles = {
home: t('titles.home'), home: t('titles.filiale'),
aktionen: t('titles.aktionen'), aktionen: t('titles.home'),
filiale: t('titles.filiale') filiale: t('titles.aktionen')
}; };
// Define all content boxes for layered rendering // Define all content boxes for layered rendering