From a180d3bb8299eb580ed56dcade74a85e3315d573 Mon Sep 17 00:00:00 2001 From: zino Date: Wed, 4 Aug 2021 19:09:59 +0200 Subject: [PATCH] changed price in legend to highest price in venue pricescale config so that we dont rely anymore on manual ref_price --- client/src/modules/cart.ts | 9 ++++----- client/src/modules/legend.ts | 27 ++++++++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/client/src/modules/cart.ts b/client/src/modules/cart.ts index 1491e24..3e9f0d1 100644 --- a/client/src/modules/cart.ts +++ b/client/src/modules/cart.ts @@ -49,7 +49,7 @@ export function calcOverallPrice(): void { else config.state.priceOverall = sumSeatPrices(); - config.state.priceOverallEur = getPriceInEur(config.state.priceOverall); + config.state.priceOverallEur = getPriceInEur(config.state.priceOverall)!; } export function generateCartItems(): void { @@ -79,9 +79,8 @@ 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 = parseFloat(inPrice); - return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(price); +export function getPriceInEur(inPrice: string | undefined): string | undefined { + return inPrice ? new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(parseFloat(inPrice)) : undefined; } export function setImportantNote(): void { @@ -119,7 +118,7 @@ function addDropdownBuyerTypeOptions(inBuyerTypes: I.TypeBuyerType, inSelector: function appendOption(inSelector: string, inArr: I.TypeBuyerTypeArr): void { const desc: string = Utils.encodeCP850DecodeUTF8(inArr[2]); const id: string = inArr[0]; - const price: string = getPriceInEur(inArr[1]); + const price: string = getPriceInEur(inArr[1])!; const dropdownBuyerTypes: HTMLElement = jQuery(inSelector).get(0); let opt: HTMLOptionElement = document.createElement('option'); diff --git a/client/src/modules/legend.ts b/client/src/modules/legend.ts index f80d40e..7ef2119 100644 --- a/client/src/modules/legend.ts +++ b/client/src/modules/legend.ts @@ -18,14 +18,11 @@ export function convertLegendToDropdown(inID: string): void { } export function generateLegend(inNode: string): I.JSCLegend { - const seatmapXML: any = config.state.seatmapXML; - const venueXML: I.VenueXML = config.state.inVenueXML!; - const pricescaleArr: I.SeatmapPricescale[] = seatmapXML.seatmap[0].pricescale_config[0].pricescale; - const venuePricescaleArr: I.Pricescale2[] = venueXML.venue[0].pricescales[0].pricescale; + return { node: jQuery(inNode), - items: createLegendItems(pricescaleArr, venuePricescaleArr) + items: createLegendItems() } } @@ -87,13 +84,25 @@ function appendFirstLegendOption(inSelect: JQuery): void { inSelect.append(option); } -function createLegendItems(pricescaleArr: I.SeatmapPricescale[], venuePricescaleArr: I.Pricescale2[]): string[][] { +function createLegendItems(): string[][] { + const seatmapXML: any = config.state.seatmapXML; + const venueXML: I.VenueXML = config.state.inVenueXML!; + const pricescaleArr: I.SeatmapPricescale[] = seatmapXML.seatmap[0].pricescale_config[0].pricescale; + const venuePricescaleArr: I.Pricescale2[] = venueXML.venue[0].pricescales[0].pricescale; + return pricescaleArr.map((arr, index: number) => { - const id: string = arr.id[0]; + // feature: get most expensive price so we dont need to rely on ref_price which needs manual entry + const mostExpensivePrice = venueXML.price_structure[0].pricescale.find(obj => { + return obj.id[0] === arr.id[0]; + })?.buyer_type.reduce((prev, current) => { + return (parseFloat(prev.price[0]) > parseFloat(current.price[0])) ? prev : current + }).price[0]; + + const price: string = Cart.getPriceInEur(mostExpensivePrice)!; // changed to highest price instead of ref_price const seatsKey: string = String.fromCharCode(97 + index).toLocaleUpperCase(); - const desc: string | undefined = Utils.encodeCP850DecodeUTF8(venuePricescaleArr.find(obj => obj.id[0] === id)?.desc[0]!); - const price: string = Cart.getPriceInEur(pricescaleArr[index].ref_price[0]); + const desc: string | undefined = Utils.encodeCP850DecodeUTF8(venuePricescaleArr.find(obj => obj.id[0] === arr.id[0])?.desc[0]!); const description: string = `${desc} ${price}`; + return [seatsKey, "available", description]; }); } \ No newline at end of file