diff --git a/client/src/modules/cart.ts b/client/src/modules/cart.ts index d5eb346..1491e24 100644 --- a/client/src/modules/cart.ts +++ b/client/src/modules/cart.ts @@ -17,12 +17,10 @@ export function addItem(inSeatObj: I.JSCSelectedSeat): void { const cartID: string = `cartItem-${inSeatObj.id}`; const dropdownBuyerTypesSelector: string = `#${cartID} .dropdownBuyerTypes`; - console.log(category); - console.log(seatStr); - appendHTML(cartID, color, category, seatStr); addDropdownBuyerTypeOptions(buyerTypes, dropdownBuyerTypesSelector); Events.addCartDropdownBuyerTypes(dropdownBuyerTypesSelector, inSeatObj); + //jQuery(".dropdownBuyerTypes").trigger("change"); // refresh cart because of highest buyer type sort => we dont need this because we add mostExpensiveBuyerTypeID now } export function removeCartItems(): void { @@ -32,9 +30,7 @@ export function removeCartItems(): void { } export function changedDropdownBuyerType(inSelect: HTMLSelectElement, inSeatObj: I.JSCSelectedSeat): void { - const index: number = config.state.selectedSeatsArr.findIndex(arr => - arr[0] === inSeatObj.id); - + const index: number = config.state.selectedSeatsArr.findIndex(arr => arr[0] === inSeatObj.id); config.state.selectedSeatsArr[index][1] = inSelect.value; const buyerTypeCode = XMLHelper.getBuyerTypeCodeByBuyerTypeID(inSelect.value); @@ -43,7 +39,6 @@ export function changedDropdownBuyerType(inSelect: HTMLSelectElement, inSeatObj: calcOverallPrice(); CartButtons.setBtnCartText(); - const url = generateCheckoutUrl(); Events.addRedirectCheckout(url); } @@ -113,8 +108,6 @@ function addDropdownBuyerTypeOptions(inBuyerTypes: I.TypeBuyerType, inSelector: if (!inBuyerTypes) return; - console.log(inBuyerTypes); - inBuyerTypes.sort((a, b) => { return b[1] - a[1]; }).forEach(arr => { @@ -129,8 +122,6 @@ function appendOption(inSelector: string, inArr: I.TypeBuyerTypeArr): void { 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}`; @@ -152,7 +143,6 @@ function getSeatPrice(arr: string[]) { if (pricescaleObj) { const seatPrice: number | undefined = XMLHelper.getPriceByBuyerTypeID(buyertypeID, pricescaleObj); - if (seatPrice) return seatPrice; } diff --git a/client/src/modules/events.ts b/client/src/modules/events.ts index e909fca..c8cf591 100644 --- a/client/src/modules/events.ts +++ b/client/src/modules/events.ts @@ -44,7 +44,7 @@ export function addModalCart(): void { export function addRedirectCheckout(inUrl: string | undefined): void { if (!inUrl) return; - + const btnCheckout = jQuery("#modalCart-overlay #checkout .fl-button").get(0); if (btnCheckout) { btnCheckout.addEventListener("click", () => { diff --git a/client/src/modules/state.ts b/client/src/modules/state.ts index cf45bca..ef9ceaf 100644 --- a/client/src/modules/state.ts +++ b/client/src/modules/state.ts @@ -9,9 +9,13 @@ export function addSeatToState(inSelectedSeat: I.JSCSelectedSeat): void { const pricescaleObj: I.Pricescale5 | undefined = XMLHelper.getVenuePriceStructurePropertyByPricescaleID(pricescaleID); if (pricescaleObj) { - const firstBuyerTypeID: string = pricescaleObj.buyer_type[0].id[0]; - const buyerTypeCode: string | undefined = XMLHelper.getBuyerTypeCodeByBuyerTypeID(firstBuyerTypeID); - const selectedSeatsArrItem: (string | undefined)[] = [inSelectedSeat.id, firstBuyerTypeID, buyerTypeCode]; + //const firstBuyerTypeID: string = pricescaleObj.buyer_type[0].id[0]; // needs to be highest amount + const mostExpensiveBuyerTypeID: string = pricescaleObj.buyer_type.reduce((prev, current) => { + return (prev.price[0] > current.price[0]) ? prev : current + }).id[0] + + const buyerTypeCode: string | undefined = XMLHelper.getBuyerTypeCodeByBuyerTypeID(mostExpensiveBuyerTypeID); + const selectedSeatsArrItem: (string | undefined)[] = [inSelectedSeat.id, mostExpensiveBuyerTypeID, buyerTypeCode]; addSeatsItemToState(selectedSeatsArrItem); } else