Compare commits

...

2 Commits

2 changed files with 74 additions and 7 deletions

View File

@@ -343,11 +343,32 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
return;
}
// Validate GTIN format (must be numeric and proper length)
// Validate GTIN format and checksum
const gtinString = product.gtin.toString().trim();
const isValidGtin = /^\d{8}$|^\d{12}$|^\d{13}$|^\d{14}$/.test(gtinString);
if (!isValidGtin) {
// Helper function to validate GTIN with proper checksum validation
const isValidGTIN = (gtin) => {
if (!/^\d{8}$|^\d{12,14}$/.test(gtin)) return false; // Only 8, 12, 13, 14 digits allowed
const digits = gtin.split('').map(Number);
const length = digits.length;
let sum = 0;
for (let i = 0; i < length - 1; i++) {
// Even/odd multiplier depends on GTIN length
let multiplier = 1;
if (length === 8) {
multiplier = (i % 2 === 0) ? 3 : 1;
} else {
multiplier = ((length - i) % 2 === 0) ? 3 : 1;
}
sum += digits[i] * multiplier;
}
const checkDigit = (10 - (sum % 10)) % 10;
return checkDigit === digits[length - 1];
};
if (!isValidGTIN(gtinString)) {
skippedCount++;
return;
}
@@ -404,8 +425,8 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
return;
}
// Generate GTIN/EAN if available
const gtin = product.gtin ? escapeXml(product.gtin.toString().trim()) : null;
// Generate GTIN/EAN if available (use the already validated gtinString)
const gtin = gtinString ? escapeXml(gtinString) : null;
// Generate product ID (using articleNumber or seoName)
const rawProductId = product.articleNumber || product.seoName || `product_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;

View File

@@ -23,8 +23,12 @@ export class LanguageProvider extends Component {
this.state = {
currentLanguage,
availableLanguages: ['ar', 'bg', 'cs', 'de', 'el', 'en', 'es', 'fr', 'hr', 'hu', 'it', 'pl', 'ro', 'ru', 'sk', 'sl', 'sr', 'sv', 'tr', 'uk', 'zh']
availableLanguages: ['ar', 'bg', 'cs', 'de', 'el', 'en', 'es', 'fr', 'hr', 'hu', 'it', 'pl', 'ro', 'ru', 'sk', 'sl', 'sr', 'sv', 'tr', 'uk', 'zh'],
demoMode: false, // Enable demo mode
currentLanguageIndex: 0
};
this.demoInterval = null;
}
componentDidMount() {
@@ -33,6 +37,11 @@ export class LanguageProvider extends Component {
// Set initial language state and HTML attribute
this.setState({ currentLanguage: this.props.i18n.language });
document.documentElement.lang = this.props.i18n.language;
// Start demo mode
if (this.state.demoMode) {
this.startDemo();
}
}
}
@@ -40,8 +49,38 @@ export class LanguageProvider extends Component {
if (this.props.i18n) {
this.props.i18n.off('languageChanged', this.handleLanguageChanged);
}
// Clean up demo interval
if (this.demoInterval) {
clearInterval(this.demoInterval);
}
}
startDemo = () => {
// Find current language index
const currentIndex = this.state.availableLanguages.indexOf(this.state.currentLanguage);
this.setState({ currentLanguageIndex: currentIndex >= 0 ? currentIndex : 0 });
this.demoInterval = setInterval(() => {
const nextIndex = (this.state.currentLanguageIndex + 1) % this.state.availableLanguages.length;
const nextLanguage = this.state.availableLanguages[nextIndex];
this.setState({ currentLanguageIndex: nextIndex });
if (this.props.i18n) {
this.props.i18n.changeLanguage(nextLanguage);
}
}, 5000); // Change language every 5 seconds
};
stopDemo = () => {
if (this.demoInterval) {
clearInterval(this.demoInterval);
this.demoInterval = null;
}
this.setState({ demoMode: false });
};
handleLanguageChanged = (lng) => {
this.setState({ currentLanguage: lng });
@@ -87,6 +126,11 @@ export class LanguageProvider extends Component {
changeLanguage = (language) => {
if (this.props.i18n && this.state.availableLanguages.includes(language)) {
// Stop demo mode if user manually changes language
if (this.state.demoMode) {
this.stopDemo();
}
this.props.i18n.changeLanguage(language);
}
};
@@ -95,7 +139,9 @@ export class LanguageProvider extends Component {
const contextValue = {
currentLanguage: this.state.currentLanguage,
changeLanguage: this.changeLanguage,
availableLanguages: this.state.availableLanguages
availableLanguages: this.state.availableLanguages,
demoMode: this.state.demoMode,
stopDemo: this.stopDemo
};
return (