changed price in legend to highest price in venue pricescale config so that we dont rely anymore on manual ref_price

This commit is contained in:
zino
2021-08-04 19:09:59 +02:00
parent d95c1d00c5
commit a180d3bb82
2 changed files with 22 additions and 14 deletions

View File

@@ -49,7 +49,7 @@ export function calcOverallPrice(): void {
else else
config.state.priceOverall = sumSeatPrices(); config.state.priceOverall = sumSeatPrices();
config.state.priceOverallEur = getPriceInEur(config.state.priceOverall); config.state.priceOverallEur = getPriceInEur(config.state.priceOverall)!;
} }
export function generateCartItems(): void { 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`; return `${inputsWithValue["ticketPurchaseUrl"]}?user_context=${inputsWithValue.user_context}&pid=${inputsWithValue["pid"]}&selected_seat_indexes=${selectedSeatIndexes}&trxstate=148`;
} }
export function getPriceInEur(inPrice: string): string { export function getPriceInEur(inPrice: string | undefined): string | undefined {
const price: number = parseFloat(inPrice); return inPrice ? new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(parseFloat(inPrice)) : undefined;
return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(price);
} }
export function setImportantNote(): void { export function setImportantNote(): void {
@@ -119,7 +118,7 @@ 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 = getPriceInEur(<string>inArr[1]); const price: string = getPriceInEur(<string>inArr[1])!;
const dropdownBuyerTypes: HTMLElement = jQuery(inSelector).get(0); const dropdownBuyerTypes: HTMLElement = jQuery(inSelector).get(0);
let opt: HTMLOptionElement = document.createElement('option'); let opt: HTMLOptionElement = document.createElement('option');

View File

@@ -18,14 +18,11 @@ export function convertLegendToDropdown(inID: string): void {
} }
export function generateLegend(inNode: string): I.JSCLegend { 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 <I.JSCLegend>{ return <I.JSCLegend>{
node: jQuery(inNode), node: jQuery(inNode),
items: createLegendItems(pricescaleArr, venuePricescaleArr) items: createLegendItems()
} }
} }
@@ -87,13 +84,25 @@ function appendFirstLegendOption(inSelect: JQuery<HTMLSelectElement>): void {
inSelect.append(option); 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) => { 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 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] === arr.id[0])?.desc[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];
}); });
} }