From 5c2b4172da2159ce32e3a88a9ac22c4dbab45c1e Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Fri, 18 Jul 2025 13:13:37 +0200 Subject: [PATCH] Enhance GTIN validation in product XML generation: Updated logic in feeds.cjs to skip products with invalid GTIN formats, ensuring only valid products are included in the generated XML. This improves data integrity for SEO purposes. --- prerender/seo/feeds.cjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/prerender/seo/feeds.cjs b/prerender/seo/feeds.cjs index b0ada0e..9f505e4 100644 --- a/prerender/seo/feeds.cjs +++ b/prerender/seo/feeds.cjs @@ -337,11 +337,20 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => { return; } - // Skip products without GTIN + // Skip products without GTIN or with invalid GTIN if (!product.gtin || !product.gtin.toString().trim()) { skippedCount++; return; } + + // Validate GTIN format (must be numeric and proper length) + const gtinString = product.gtin.toString().trim(); + const isValidGtin = /^\d{8}$|^\d{12}$|^\d{13}$|^\d{14}$/.test(gtinString); + + if (!isValidGtin) { + skippedCount++; + return; + } // Skip products without pictures if (!product.pictureList || !product.pictureList.trim()) {