Compare commits
2 Commits
04e97c2522
...
8bc80c872d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bc80c872d | ||
|
|
85504c725f |
@@ -343,11 +343,32 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate GTIN format (must be numeric and proper length)
|
// Validate GTIN format and checksum
|
||||||
const gtinString = product.gtin.toString().trim();
|
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++;
|
skippedCount++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -404,8 +425,8 @@ const generateProductsXml = (allProductsData = [], baseUrl, config) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate GTIN/EAN if available
|
// Generate GTIN/EAN if available (use the already validated gtinString)
|
||||||
const gtin = product.gtin ? escapeXml(product.gtin.toString().trim()) : null;
|
const gtin = gtinString ? escapeXml(gtinString) : null;
|
||||||
|
|
||||||
// Generate product ID (using articleNumber or seoName)
|
// Generate product ID (using articleNumber or seoName)
|
||||||
const rawProductId = product.articleNumber || product.seoName || `product_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;
|
const rawProductId = product.articleNumber || product.seoName || `product_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;
|
||||||
|
|||||||
@@ -23,8 +23,12 @@ export class LanguageProvider extends Component {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
currentLanguage,
|
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() {
|
componentDidMount() {
|
||||||
@@ -33,6 +37,11 @@ export class LanguageProvider extends Component {
|
|||||||
// Set initial language state and HTML attribute
|
// Set initial language state and HTML attribute
|
||||||
this.setState({ currentLanguage: this.props.i18n.language });
|
this.setState({ currentLanguage: this.props.i18n.language });
|
||||||
document.documentElement.lang = this.props.i18n.language;
|
document.documentElement.lang = this.props.i18n.language;
|
||||||
|
|
||||||
|
// Start demo mode
|
||||||
|
if (this.state.demoMode) {
|
||||||
|
this.startDemo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +49,37 @@ export class LanguageProvider extends Component {
|
|||||||
if (this.props.i18n) {
|
if (this.props.i18n) {
|
||||||
this.props.i18n.off('languageChanged', this.handleLanguageChanged);
|
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) => {
|
handleLanguageChanged = (lng) => {
|
||||||
this.setState({ currentLanguage: lng });
|
this.setState({ currentLanguage: lng });
|
||||||
@@ -87,6 +126,11 @@ export class LanguageProvider extends Component {
|
|||||||
|
|
||||||
changeLanguage = (language) => {
|
changeLanguage = (language) => {
|
||||||
if (this.props.i18n && this.state.availableLanguages.includes(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);
|
this.props.i18n.changeLanguage(language);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -95,7 +139,9 @@ export class LanguageProvider extends Component {
|
|||||||
const contextValue = {
|
const contextValue = {
|
||||||
currentLanguage: this.state.currentLanguage,
|
currentLanguage: this.state.currentLanguage,
|
||||||
changeLanguage: this.changeLanguage,
|
changeLanguage: this.changeLanguage,
|
||||||
availableLanguages: this.state.availableLanguages
|
availableLanguages: this.state.availableLanguages,
|
||||||
|
demoMode: this.state.demoMode,
|
||||||
|
stopDemo: this.stopDemo
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user