#!/usr/bin/env node /** * Script to fix missing attributes for high-voltage cables * Creates a manual attribute mapping based on product specifications */ const fs = require('fs'); const path = require('path'); const PROCESSED_DIR = path.join(__dirname, '..', 'data', 'processed'); const BACKUP_DIR = path.join(__dirname, '..', 'data', 'backup'); // Create backup directory if (!fs.existsSync(BACKUP_DIR)) { fs.mkdirSync(BACKUP_DIR, { recursive: true }); } /** * Manual attribute mappings for high-voltage cables * Based on typical specifications for these cable types */ const MANUAL_ATTRIBUTES = { // High Voltage Cables - Aluminum conductor, XLPE insulation 'na2xsfl2y-3': { // NA2XS(FL)2Y high voltage en: [ { name: 'Conductor', options: ['Aluminum'] }, { name: 'Insulation', options: ['XLPE'] }, { name: 'Sheath', options: ['PE'] }, { name: 'Screen', options: ['Copper wire + tape'] }, { name: 'Water blocking', options: ['Yes'] }, { name: 'Voltage rating', options: ['6/10 kV', '12/20 kV', '18/30 kV'] }, { name: 'Installation', options: ['Underground', 'Cable ducts', 'Outdoor'] }, { name: 'Standard', options: ['IEC 60840', 'DIN VDE 0276-620'] }, { name: 'Conductor material', options: ['Aluminum'] }, { name: 'Conductor type', options: ['Compacted stranded'] }, { name: 'Insulation material', options: ['XLPE'] }, { name: 'Sheath material', options: ['PE'] }, { name: 'Armour', options: ['None'] }, { name: 'Max operating temperature', options: ['+90 °C'] }, { name: 'Short circuit temperature', options: ['+250 °C'] }, { name: 'Bending radius', options: ['Min. 15x diameter'] } ], de: [ { name: 'Leiter', options: ['Aluminium'] }, { name: 'Isolation', options: ['XLPE'] }, { name: 'Mantel', options: ['PE'] }, { name: 'Abschirmung', options: ['Kupferdraht + Band'] }, { name: 'Wassersperre', options: ['Ja'] }, { name: 'Spannungsbereich', options: ['6/10 kV', '12/20 kV', '18/30 kV'] }, { name: 'Installation', options: ['Unterirdisch', 'Kabelrohre', 'Außen'] }, { name: 'Norm', options: ['IEC 60840', 'DIN VDE 0276-620'] }, { name: 'Leitermaterial', options: ['Aluminium'] }, { name: 'Leitertyp', options: ['Verdrillt'] }, { name: 'Isolationsmaterial', options: ['XLPE'] }, { name: 'Mantelmaterial', options: ['PE'] }, { name: 'Bewehrung', options: ['Keine'] }, { name: 'Max. Betriebstemperatur', options: ['+90 °C'] }, { name: 'Kurzschlusstemperatur', options: ['+250 °C'] }, { name: 'Biegeradius', options: ['Min. 15x Durchmesser'] } ] }, 'n2xsfl2y': { // N2XS(FL)2Y high voltage en: [ { name: 'Conductor', options: ['Copper'] }, { name: 'Insulation', options: ['XLPE'] }, { name: 'Sheath', options: ['PE'] }, { name: 'Screen', options: ['Copper wire + tape'] }, { name: 'Water blocking', options: ['Yes'] }, { name: 'Voltage rating', options: ['6/10 kV', '12/20 kV', '18/30 kV'] }, { name: 'Installation', options: ['Underground', 'Cable ducts', 'Outdoor'] }, { name: 'Standard', options: ['IEC 60840', 'DIN VDE 0276-620'] }, { name: 'Conductor material', options: ['Copper'] }, { name: 'Conductor type', options: ['Stranded'] }, { name: 'Insulation material', options: ['XLPE'] }, { name: 'Sheath material', options: ['PE'] }, { name: 'Armour', options: ['None'] }, { name: 'Max operating temperature', options: ['+90 °C'] }, { name: 'Short circuit temperature', options: ['+250 °C'] }, { name: 'Bending radius', options: ['Min. 15x diameter'] } ], de: [ { name: 'Leiter', options: ['Kupfer'] }, { name: 'Isolation', options: ['XLPE'] }, { name: 'Mantel', options: ['PE'] }, { name: 'Abschirmung', options: ['Kupferdraht + Band'] }, { name: 'Wassersperre', options: ['Ja'] }, { name: 'Spannungsbereich', options: ['6/10 kV', '12/20 kV', '18/30 kV'] }, { name: 'Installation', options: ['Unterirdisch', 'Kabelrohre', 'Außen'] }, { name: 'Norm', options: ['IEC 60840', 'DIN VDE 0276-620'] }, { name: 'Leitermaterial', options: ['Kupfer'] }, { name: 'Leitertyp', options: ['Verdrillt'] }, { name: 'Isolationsmaterial', options: ['XLPE'] }, { name: 'Mantelmaterial', options: ['PE'] }, { name: 'Bewehrung', options: ['Keine'] }, { name: 'Max. Betriebstemperatur', options: ['+90 °C'] }, { name: 'Kurzschlusstemperatur', options: ['+250 °C'] }, { name: 'Biegeradius', options: ['Min. 15x Durchmesser'] } ] }, 'h1z2z2-k': { // H1Z2Z2-K solar cable en: [ { name: 'Conductor', options: ['Tinned copper'] }, { name: 'Insulation', options: ['XLPE'] }, { name: 'Sheath', options: ['XLPE'] }, { name: 'Voltage rating', options: ['1.5 kV'] }, { name: 'Temperature range', options: ['-40 °C to +120 °C'] }, { name: 'Standard', options: ['DIN EN 50618', 'VDE 0283-618'] }, { name: 'Flame retardant', options: ['Yes'] }, { name: 'Halogen free', options: ['Yes'] }, { name: 'UV resistant', options: ['Yes'] }, { name: 'Conductor class', options: ['Class 5'] }, { name: 'Test voltage', options: ['6.5 kV'] }, { name: 'CPR class', options: ['Eca'] } ], de: [ { name: 'Leiter', options: ['Verzinntes Kupfer'] }, { name: 'Isolation', options: ['XLPE'] }, { name: 'Mantel', options: ['XLPE'] }, { name: 'Spannungsbereich', options: ['1.5 kV'] }, { name: 'Temperaturbereich', options: ['-40 °C bis +120 °C'] }, { name: 'Norm', options: ['DIN EN 50618', 'VDE 0283-618'] }, { name: 'Flammhemmend', options: ['Ja'] }, { name: 'Halogenfrei', options: ['Ja'] }, { name: 'UV-beständig', options: ['Ja'] }, { name: 'Leiterklasse', options: ['Klasse 5'] }, { name: 'Prüfspannung', options: ['6.5 kV'] }, { name: 'CPR-Klasse', options: ['Eca'] } ] }, 'na2xfk2y': { // NA2X(F)K2Y high voltage en: [ { name: 'Conductor', options: ['Copper'] }, { name: 'Insulation', options: ['XLPE'] }, { name: 'Sheath', options: ['PVC'] }, { name: 'Screen', options: ['Copper wire'] }, { name: 'Voltage rating', options: ['64/110 kV'] }, { name: 'Installation', options: ['Underground', 'Cable ducts'] }, { name: 'Standard', options: ['IEC 60502-2'] }, { name: 'Conductor material', options: ['Copper'] }, { name: 'Insulation material', options: ['XLPE'] }, { name: 'Sheath material', options: ['PVC'] }, { name: 'Max operating temperature', options: ['+90 °C'] }, { name: 'Short circuit temperature', options: ['+250 °C'] } ], de: [ { name: 'Leiter', options: ['Kupfer'] }, { name: 'Isolation', options: ['XLPE'] }, { name: 'Mantel', options: ['PVC'] }, { name: 'Abschirmung', options: ['Kupferdraht'] }, { name: 'Spannungsbereich', options: ['64/110 kV'] }, { name: 'Installation', options: ['Unterirdisch', 'Kabelrohre'] }, { name: 'Norm', options: ['IEC 60502-2'] }, { name: 'Leitermaterial', options: ['Kupfer'] }, { name: 'Isolationsmaterial', options: ['XLPE'] }, { name: 'Mantelmaterial', options: ['PVC'] }, { name: 'Max. Betriebstemperatur', options: ['+90 °C'] }, { name: 'Kurzschlusstemperatur', options: ['+250 °C'] } ] }, 'n2xfk2y': { // N2X(F)K2Y high voltage en: [ { name: 'Conductor', options: ['Copper'] }, { name: 'Insulation', options: ['XLPE'] }, { name: 'Sheath', options: ['PVC'] }, { name: 'Screen', options: ['Copper wire'] }, { name: 'Voltage rating', options: ['64/110 kV'] }, { name: 'Installation', options: ['Underground', 'Cable ducts'] }, { name: 'Standard', options: ['IEC 60502-2'] }, { name: 'Conductor material', options: ['Copper'] }, { name: 'Insulation material', options: ['XLPE'] }, { name: 'Sheath material', options: ['PVC'] }, { name: 'Max operating temperature', options: ['+90 °C'] }, { name: 'Short circuit temperature', options: ['+250 °C'] } ], de: [ { name: 'Leiter', options: ['Kupfer'] }, { name: 'Isolation', options: ['XLPE'] }, { name: 'Mantel', options: ['PVC'] }, { name: 'Abschirmung', options: ['Kupferdraht'] }, { name: 'Spannungsbereich', options: ['64/110 kV'] }, { name: 'Installation', options: ['Unterirdisch', 'Kabelrohre'] }, { name: 'Norm', options: ['IEC 60502-2'] }, { name: 'Leitermaterial', options: ['Kupfer'] }, { name: 'Isolationsmaterial', options: ['XLPE'] }, { name: 'Mantelmaterial', options: ['PVC'] }, { name: 'Max. Betriebstemperatur', options: ['+90 °C'] }, { name: 'Kurzschlusstemperatur', options: ['+250 °C'] } ] }, 'na2xfkld2y': { // NA2X(F)KLD2Y high voltage en: [ { name: 'Conductor', options: ['Copper'] }, { name: 'Insulation', options: ['XLPE'] }, { name: 'Sheath', options: ['PE'] }, { name: 'Screen', options: ['Copper wire + tape'] }, { name: 'Voltage rating', options: ['64/110 kV'] }, { name: 'Installation', options: ['Direct burial', 'Cable tray'] }, { name: 'Standard', options: ['IEC 60502-2'] }, { name: 'Conductor material', options: ['Copper'] }, { name: 'Insulation material', options: ['XLPE'] }, { name: 'Sheath material', options: ['PE'] }, { name: 'Armour', options: ['Aluminum tape'] }, { name: 'Max operating temperature', options: ['+90 °C'] }, { name: 'Short circuit temperature', options: ['+250 °C'] } ], de: [ { name: 'Leiter', options: ['Kupfer'] }, { name: 'Isolation', options: ['XLPE'] }, { name: 'Mantel', options: ['PE'] }, { name: 'Abschirmung', options: ['Kupferdraht + Band'] }, { name: 'Spannungsbereich', options: ['64/110 kV'] }, { name: 'Installation', options: ['Direktverlegung', 'Kabeltragg'] }, { name: 'Norm', options: ['IEC 60502-2'] }, { name: 'Leitermaterial', options: ['Kupfer'] }, { name: 'Isolationsmaterial', options: ['XLPE'] }, { name: 'Mantelmaterial', options: ['PE'] }, { name: 'Bewehrung', options: ['Aluminiumband'] }, { name: 'Max. Betriebstemperatur', options: ['+90 °C'] }, { name: 'Kurzschlusstemperatur', options: ['+250 °C'] } ] }, 'n2xfkld2y': { // N2X(F)KLD2Y high voltage en: [ { name: 'Conductor', options: ['Copper'] }, { name: 'Insulation', options: ['XLPE'] }, { name: 'Sheath', options: ['PE'] }, { name: 'Screen', options: ['Copper wire + tape'] }, { name: 'Voltage rating', options: ['64/110 kV'] }, { name: 'Installation', options: ['Direct burial', 'Cable tray'] }, { name: 'Standard', options: ['IEC 60502-2'] }, { name: 'Conductor material', options: ['Copper'] }, { name: 'Insulation material', options: ['XLPE'] }, { name: 'Sheath material', options: ['PE'] }, { name: 'Armour', options: ['Aluminum tape'] }, { name: 'Max operating temperature', options: ['+90 °C'] }, { name: 'Short circuit temperature', options: ['+250 °C'] } ], de: [ { name: 'Leiter', options: ['Kupfer'] }, { name: 'Isolation', options: ['XLPE'] }, { name: 'Mantel', options: ['PE'] }, { name: 'Abschirmung', options: ['Kupferdraht + Band'] }, { name: 'Spannungsbereich', options: ['64/110 kV'] }, { name: 'Installation', options: ['Direktverlegung', 'Kabeltragg'] }, { name: 'Norm', options: ['IEC 60502-2'] }, { name: 'Leitermaterial', options: ['Kupfer'] }, { name: 'Isolationsmaterial', options: ['XLPE'] }, { name: 'Mantelmaterial', options: ['PE'] }, { name: 'Bewehrung', options: ['Aluminiumband'] }, { name: 'Max. Betriebstemperatur', options: ['+90 °C'] }, { name: 'Kurzschlusstemperatur', options: ['+250 °C'] } ] } }; function addMissingAttributes() { console.log('🔧 Fixing missing product attributes\n'); const productsPath = path.join(PROCESSED_DIR, 'products.json'); if (!fs.existsSync(productsPath)) { console.error('❌ products.json not found'); return; } // Load current products const products = JSON.parse(fs.readFileSync(productsPath, 'utf8')); console.log(`📊 Loaded ${products.length} products`); // Create backup const backupPath = path.join(BACKUP_DIR, `products-${Date.now()}.json`); fs.writeFileSync(backupPath, JSON.stringify(products, null, 2)); console.log(`💾 Backup created: ${backupPath}`); let fixedCount = 0; let alreadyFixedCount = 0; // Process each product const updatedProducts = products.map(product => { // Skip if already has attributes if (product.attributes && product.attributes.length > 0) { alreadyFixedCount++; return product; } // Find matching manual attributes const slug = product.slug; const manualSet = MANUAL_ATTRIBUTES[slug]; if (manualSet) { const attributes = product.locale === 'en' ? manualSet.en : manualSet.de; console.log(`✅ Fixed: ${product.name} (${product.locale})`); console.log(` Added ${attributes.length} attributes`); fixedCount++; return { ...product, attributes: attributes.map((attr, index) => ({ id: index, name: attr.name, slug: attr.name.toLowerCase().replace(/\s+/g, '-'), position: index, visible: true, variation: true, options: attr.options })) }; } // No manual mapping found return product; }); // Save updated products fs.writeFileSync(productsPath, JSON.stringify(updatedProducts, null, 2)); // Summary console.log('\n' + '='.repeat(60)); console.log('📊 SUMMARY'); console.log('='.repeat(60)); console.log(`Total products: ${products.length}`); console.log(`Already had attributes: ${alreadyFixedCount}`); console.log(`Fixed with manual mapping: ${fixedCount}`); console.log(`Still missing: ${products.length - alreadyFixedCount - fixedCount}`); // Show which products still need work const stillMissing = updatedProducts.filter(p => !p.attributes || p.attributes.length === 0); if (stillMissing.length > 0) { console.log('\n⚠️ Products still missing attributes:'); stillMissing.forEach(p => { console.log(` - ${p.name} (${p.slug}) [ID: ${p.id}, Locale: ${p.locale}]`); }); } console.log(`\n✅ Attribute fix complete!`); console.log(`💾 Updated file: ${productsPath}`); } // Run if called directly if (require.main === module) { addMissingAttributes(); } module.exports = { addMissingAttributes, MANUAL_ATTRIBUTES };