diff --git a/client/src/modules/cart.ts b/client/src/modules/cart.ts index c761129..d5eb346 100644 --- a/client/src/modules/cart.ts +++ b/client/src/modules/cart.ts @@ -5,14 +5,14 @@ import * as Events from "./events"; import * as CartButtons from "./cartButtons"; import Utils from "./utils"; -export function addItem(inSeatObj: I.JSCSelectedSeat): void { +export function addItem(inSeatObj: I.JSCSelectedSeat): void { const color: string = `#${XMLHelper.getVenuePricescalePropertyByPricescaleID("color", inSeatObj.data.seatsObj.id[0])}`; - const category: string | undefined = Utils.encodeCP850DecodeUTF8( XMLHelper.getVenuePricescalePropertyByPricescaleID("desc", inSeatObj.data.seatsObj.id[0])! ); + const category: string | undefined = Utils.encodeCP850DecodeUTF8(XMLHelper.getVenuePricescalePropertyByPricescaleID("desc", inSeatObj.data.seatsObj.id[0])!); const seat: string = config.state.layoutRows[inSeatObj.id][5]; const row: string = config.state.layoutRows[inSeatObj.id][4]; const sectionID: string = config.state.layoutRows[inSeatObj.id][3]; const sectionDesc: string | undefined = XMLHelper.getSectionDescBySectionID(sectionID); - const seatStr: string | undefined = Utils.encodeCP850DecodeUTF8( `${sectionDesc}
Reihe ${row} Platz ${seat}` ); + const seatStr: string | undefined = Utils.encodeCP850DecodeUTF8(`${sectionDesc}
Reihe ${row} Platz ${seat}`); const buyerTypes: I.TypeBuyerType = XMLHelper.getBuyerTypesByPricescaleID(inSeatObj.data.seatsObj.id[0]); const cartID: string = `cartItem-${inSeatObj.id}`; const dropdownBuyerTypesSelector: string = `#${cartID} .dropdownBuyerTypes`; @@ -48,7 +48,7 @@ export function changedDropdownBuyerType(inSelect: HTMLSelectElement, inSeatObj: Events.addRedirectCheckout(url); } -export function calcOverallPrice(): void{ +export function calcOverallPrice(): void { if (!config.state.selectedSeatsArr.length) config.state.priceOverall = "0"; else @@ -113,20 +113,24 @@ function addDropdownBuyerTypeOptions(inBuyerTypes: I.TypeBuyerType, inSelector: if (!inBuyerTypes) return; - inBuyerTypes.forEach(arr => { + console.log(inBuyerTypes); + + inBuyerTypes.sort((a, b) => { + return b[1] - a[1]; + }).forEach(arr => { if (arr[0]) appendOption(inSelector, arr) }); } function appendOption(inSelector: string, inArr: I.TypeBuyerTypeArr): void { - const desc: string = Utils.encodeCP850DecodeUTF8( inArr[2] ); + const desc: string = Utils.encodeCP850DecodeUTF8(inArr[2]); const id: string = inArr[0]; const price: string = getPriceInEur(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}`; @@ -141,17 +145,17 @@ function sumSeatPrices(): string { function getSeatPrice(arr: string[]) { const seatID: string = arr[0]; - const buyertypeID: string = arr[1]; - const selectedSeat: I.JSCSelectedSeat = config.state.selectedSeatsObj[seatID]; - const pricescaleID: string = selectedSeat.data.seatsObj.id[0]; - const pricescaleObj: I.Pricescale5 | undefined = XMLHelper.getVenuePriceStructurePropertyByPricescaleID(pricescaleID); + const buyertypeID: string = arr[1]; + const selectedSeat: I.JSCSelectedSeat = config.state.selectedSeatsObj[seatID]; + const pricescaleID: string = selectedSeat.data.seatsObj.id[0]; + const pricescaleObj: I.Pricescale5 | undefined = XMLHelper.getVenuePriceStructurePropertyByPricescaleID(pricescaleID); - if (pricescaleObj) { - const seatPrice: number | undefined = XMLHelper.getPriceByBuyerTypeID(buyertypeID, pricescaleObj); + if (pricescaleObj) { + const seatPrice: number | undefined = XMLHelper.getPriceByBuyerTypeID(buyertypeID, pricescaleObj); - if (seatPrice) - return seatPrice; - } + if (seatPrice) + return seatPrice; + } - return 0; + return 0; } \ No newline at end of file