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

60
client/dist/inject.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -48,14 +48,13 @@ export function changedDropdownBuyerType(inSelect: HTMLSelectElement, inSeatObj:
Events.addRedirectCheckout(url); Events.addRedirectCheckout(url);
} }
export function calcOverallPrice(): string | undefined { export function calcOverallPrice(): void{
if (!config.state.selectedSeatsArr.length) { if (!config.state.selectedSeatsArr.length)
config.state.priceOverall = "0"; config.state.priceOverall = "0";
return "0"; else
} config.state.priceOverall = sumSeatPrices();
config.state.priceOverall = sumSeatPrices(); config.state.priceOverallEur = getPriceInEur(config.state.priceOverall);
return 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`; 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 { function appendHTML(inCartID: string, inColor: string, inCategory: string | undefined, inSeatStr: string): void {
jQuery("#cartItemHTML .fl-html").append(` jQuery("#cartItemHTML .fl-html").append(`
<div class="cartItem" id="${inCartID}"> <div class="cartItem" id="${inCartID}">
@@ -110,12 +114,14 @@ function addDropdownBuyerTypeOptions(inBuyerTypes: I.TypeBuyerType, inSelector:
function appendOption(inSelector: string, inArr: I.TypeBuyerTypeArr): void { function appendOption(inSelector: string, inArr: I.TypeBuyerTypeArr): void {
const desc: string = Utils.encodeCP850DecodeUTF8( <string>inArr[2] ); const desc: string = Utils.encodeCP850DecodeUTF8( <string>inArr[2] );
const id: string = <string>inArr[0]; 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); const dropdownBuyerTypes: HTMLElement = jQuery(inSelector).get(0);
console.log(price);
let opt: HTMLOptionElement = document.createElement('option'); let opt: HTMLOptionElement = document.createElement('option');
opt.value = id; opt.value = id;
opt.innerHTML = `${desc} ${price}`; opt.innerHTML = `${desc} ${price}`;
dropdownBuyerTypes.appendChild(opt); dropdownBuyerTypes.appendChild(opt);
} }

View File

@@ -7,20 +7,18 @@ export function setBtnCartText(): void {
function createCartBtnText(): string { function createCartBtnText(): string {
const numTickets: number = config.state.selectedSeatsArr.length; const numTickets: number = config.state.selectedSeatsArr.length;
return numTickets === 1 ? `${numTickets} Ticket für ${config.state.priceOverallEur}` : `${numTickets} Tickets für ${config.state.priceOverallEur}`;
if (config.state.priceOverall !== "")
return numTickets === 1 ? `${numTickets} Ticket für €${config.state.priceOverall}` : `${numTickets} Tickets für €${config.state.priceOverall}`;
else
return "0 Tickets für €0.00";
} }
function createModalCartBtnText(): string { function createModalCartBtnText(): string {
const numTickets: number = config.state.selectedSeatsArr.length; const numTickets: number = config.state.selectedSeatsArr.length;
if (config.state.priceOverall !== "") return `Summe (${numTickets} Plätze) ${config.state.priceOverallEur}`;
return `Summe (${numTickets} Plätze) €${config.state.priceOverall}`;
else // if (config.state.priceOverall !== "")
return `Summe (0 Plätze) €0,00`; // return `Summe (${numTickets} Plätze) €${config.state.priceOverall}`;
// else
// return `Summe (0 Plätze) €0,00`;
} }
export function showHideBtnCartLoading(inSwitch: string): void { export function showHideBtnCartLoading(inSwitch: string): void {

View File

@@ -28,6 +28,7 @@ export const config: I.Config = {
}, },
state: { state: {
priceOverall: "", priceOverall: "",
priceOverallEur: "",
cartChanged: false, cartChanged: false,
selectedSeatsArr: [], selectedSeatsArr: [],
selectedSeatsObj: {}, selectedSeatsObj: {},

View File

@@ -1,6 +1,7 @@
import { config } from "./config"; import { config } from "./config";
import * as I from "../types/types"; import * as I from "../types/types";
import Utils from "./utils"; import Utils from "./utils";
import * as Cart from "./cart";
export function convertLegendToDropdown(inID: string): void { export function convertLegendToDropdown(inID: string): void {
jQuery('ul.seatCharts-legendList').each(function () { jQuery('ul.seatCharts-legendList').each(function () {
@@ -69,8 +70,8 @@ function createLegendItems(pricescaleArr: I.SeatmapPricescale[], venuePricescale
const id: string = arr.id[0]; const id: string = arr.id[0];
const seatsKey: string = String.fromCharCode(97 + index).toLocaleUpperCase(); const seatsKey: string = String.fromCharCode(97 + index).toLocaleUpperCase();
const desc: string | undefined = Utils.encodeCP850DecodeUTF8( venuePricescaleArr.find(obj => obj.id[0] === id)?.desc[0]! ); const desc: string | undefined = Utils.encodeCP850DecodeUTF8( venuePricescaleArr.find(obj => obj.id[0] === id)?.desc[0]! );
const price: string = pricescaleArr[index].ref_price[0]; const price: string = Cart.getPriceInEur(pricescaleArr[index].ref_price[0]);
const description: string = `${desc} ${price}`; const description: string = `${desc} ${price}`;
return [seatsKey, "available", description]; return [seatsKey, "available", description];
}); });
} }

View File

@@ -12,6 +12,7 @@ export interface Trim {
} }
export interface State { export interface State {
priceOverallEur: string;
priceOverall: string; priceOverall: string;
cartChanged: boolean; cartChanged: boolean;
selectedSeatsArr: string[][]; selectedSeatsArr: string[][];