replaced hardcoded € with intl.numberformat and created config .state.priceOverallInEur

This commit is contained in:
zino
2021-05-27 11:12:05 +02:00
parent 01560a5c20
commit 6ba97e46f7
7 changed files with 106 additions and 59 deletions

View File

@@ -48,14 +48,13 @@ export function changedDropdownBuyerType(inSelect: HTMLSelectElement, inSeatObj:
Events.addRedirectCheckout(url);
}
export function calcOverallPrice(): string | undefined {
if (!config.state.selectedSeatsArr.length) {
export function calcOverallPrice(): void{
if (!config.state.selectedSeatsArr.length)
config.state.priceOverall = "0";
return "0";
}
else
config.state.priceOverall = sumSeatPrices();
config.state.priceOverall = sumSeatPrices();
return config.state.priceOverall;
config.state.priceOverallEur = getPriceInEur(config.state.priceOverall);
}
@@ -86,6 +85,11 @@ export function generateCheckoutUrl(): string | undefined {
return `${inputsWithValue["ticketPurchaseUrl"]}?user_context=${inputsWithValue.user_context}&pid=${inputsWithValue["pid"]}&selected_seat_indexes=${selectedSeatIndexes}&trxstate=148`;
}
export function getPriceInEur(inPrice: string): string {
const price: number = parseInt(inPrice);
return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(price);
}
function appendHTML(inCartID: string, inColor: string, inCategory: string | undefined, inSeatStr: string): void {
jQuery("#cartItemHTML .fl-html").append(`
<div class="cartItem" id="${inCartID}">
@@ -110,12 +114,14 @@ function addDropdownBuyerTypeOptions(inBuyerTypes: I.TypeBuyerType, inSelector:
function appendOption(inSelector: string, inArr: I.TypeBuyerTypeArr): void {
const desc: string = Utils.encodeCP850DecodeUTF8( <string>inArr[2] );
const id: string = <string>inArr[0];
const price: string = <string>inArr[1];
const price: string = getPriceInEur(<string>inArr[1]);
const dropdownBuyerTypes: HTMLElement = jQuery(inSelector).get(0);
console.log(price);
let opt: HTMLOptionElement = document.createElement('option');
opt.value = id;
opt.innerHTML = `${desc} ${price}`;
opt.innerHTML = `${desc} ${price}`;
dropdownBuyerTypes.appendChild(opt);
}