GrowRoom21 - Tu socio competente para head, grow, plantas de cáñamo y semillas
13;
var specialPrice = 0;
var isWholesale = false;
var wholesalerLevel = 0;
var isAustria = false;
// Großhandelspreise (wenn verfügbar)
var wholesalePrices = [];
wholesalePrices = ["8.7611"];
console.log('Base Price:', basePrice, 'Special Price:', specialPrice, 'Tax Rate:', taxRate,
'Is Wholesale:', isWholesale, 'Is Austria:', isAustria, 'Wholesaler Level:', wholesalerLevel,
'Wholesale Prices:', wholesalePrices);
function updatePrice() {
var finalPrice = 0;
var hasAttributes = false;
var selectedAttributeOptions = [];
var pricePrefix = '';
var vatText = '';
var includeTax = !isWholesale || (isWholesale && isAustria);
// Sammle alle ausgewählten Attributoptionen
attributeSelects.forEach(function(select) {
var selectedOption = select.options[select.selectedIndex];
var optionText = selectedOption.text;
// Extrahiere den Preis aus dem Optionstext (Format: "Option (XX,XX €)")
var priceMatch = optionText.match(/\(([0-9,.]+)\s*€\)/);
if (priceMatch && priceMatch[1]) {
hasAttributes = true;
// Konvertiere den gefundenen Preis in eine Zahl
var optionPrice = parseFloat(priceMatch[1].replace(',', '.'));
console.log('Option:', optionText, 'Extracted Price:', optionPrice);
selectedAttributeOptions.push({
text: optionText,
price: optionPrice
});
}
});
// Preisberechnung basierend auf Kundentyp und Land
if (isWholesale && wholesalerLevel > 0) {
// Großhandelspreis
if (wholesalePrices.length > 0 && wholesalePrices[wholesalerLevel - 1] && wholesalePrices[wholesalerLevel - 1] != '0.00') {
// Verwenden Sie den Großhandelspreis (dieser ist netto)
finalPrice = parseFloat(wholesalePrices[wholesalerLevel - 1]);
console.log('Wholesale price before tax:', finalPrice);
// Für österreichische Großhändler: Mehrwertsteuer hinzufügen
if (isAustria) {
// Steuern explizit hinzufügen
var taxAmount = finalPrice * (taxRate / 100);
finalPrice = finalPrice + taxAmount;
console.log('Tax amount:', taxAmount);
console.log('Wholesale price after tax:', finalPrice);
pricePrefix = 'Großhandelspreis: ';
vatText = 'Inkl. ' + taxRate.toFixed(1).replace('.', ',') + '% MwSt.';
} else {
// Nicht-österreichische Großhändler: Nettopreis anzeigen
pricePrefix = 'Großhandelspreis: ';
vatText = 'Nettopreis (exkl. MwSt.)';
}
} else {
// Fallback auf normalen Preis
finalPrice = hasAttributes && selectedAttributeOptions.length > 0 ?
selectedAttributeOptions[0].price :
(specialPrice > 0 ? specialPrice : basePrice);
console.log('Using regular price (fallback):', finalPrice);
// Für österreichische Kunden: Mehrwertsteuer hinzufügen, falls nötig
if (isAustria) {
if (!hasAttributes) {
// Bei Attributen ist der Preis bereits korrekt
finalPrice = finalPrice * (1 + (taxRate / 100));
}
pricePrefix = '';
vatText = 'Inkl. ' + taxRate.toFixed(1).replace('.', ',') + '% MwSt.';
} else {
pricePrefix = 'Großhandelspreis: ';
vatText = 'Nettopreis (exkl. MwSt.)';
}
}
} else {
// Retail-Kunde
finalPrice = hasAttributes && selectedAttributeOptions.length > 0 ?
selectedAttributeOptions[0].price :
(specialPrice > 0 ? specialPrice : basePrice);
// Bei Retail-Kunden ist der Preis immer inklusive Steuern
if (!hasAttributes && !specialPrice) {
finalPrice = finalPrice * (1 + (taxRate / 100));
}
pricePrefix = ''; // Kein Prefix für den Normalpreis
vatText = 'Inkl. ' + taxRate.toFixed(1).replace('.', ',') + '% MwSt.';
}
// Preis formatieren und anzeigen
if (finalPrice > 0) {
priceElement.innerHTML = pricePrefix + formatCurrency(finalPrice);
if (vatTextElement) {
vatTextElement.innerHTML = vatText;
}
} else {
priceElement.innerHTML = 'Preis auf Anfrage';
}
}
function formatCurrency(amount) {
return amount.toFixed(2).replace('.', ',') + ' €';
}
// Event-Listener für Attributänderungen
attributeSelects.forEach(function(select) {
select.addEventListener('change', updatePrice);
});
// Initiale Preisaktualisierung
updatePrice();
// Debug-Ausgabe für alle Attribute
attributeSelects.forEach(function(select) {
console.log('Attribute Select:', select.name);
Array.from(select.options).forEach(function(option) {
console.log(' Option:', option.text, 'Price Modifier:', option.getAttribute('data-price-modifier'));
});
});
});