{"version":3,"sources":["estore/cart/detailed-cart-controller.ts"],"names":["cartEventPublisher","cartEventSubscriber","CartService","Notify","DiscountCouponsApi","CouponDiscountsHelper","Locale","determineTranslation","FreeShippingApi","convertStringToNumber","DetailedCartController","constructor","this","translations","En","couponNotFound","codeWasNotActivated","alreadyApliedMessage","youHaveBetterDiscountCodeMessage","No","labels","_inclVat","window","globalSettings","displayPricesIncludingVat","_freeShipipngApi","_cartService","_discountCouponsApi","_appliedCodesName","_applyCodesResult","undefined","_detailedCartInfo","_couponDiscounts","cartSettings","instance","_getData","initEventSubscibtions","Error","onCartItemsAdded","_onCartItemsAdded","bind","onCartItemsRemoved","_onCartItemsRemoved","onCartEmptied","_onCartEmptied","onCartQuantityUpdated","_onCartQuantityUpdated","getDetailedCartInfo","countSingles","line","quantity","factor","countPackages","Math","floor","removeLine","await","removeFromCart","tempOrderLineID","error","success","console","clearCart","emptyCart","updateQuantity","_updateCartLine","onFactorInputChange","oldPackageQuantity","Number","onFractionInputChange","oldSinglesQuantity","createOffer","getSessionCouponDiscounts","sessionCouponDiscounts","selectDiscount","codeID","selectCouponDiscount","_updateStates","unselectDiscount","unselectCouponDiscount","getOrderDiscountVisibility","appliedDiscountInfo","getSelectedCombination","codesInfo","length","orderPrice","generalOrderDiscounts","topic","eventData","_updateDetailedCartInfo","result","detailedCartInfo","then","couponCodes","map","discountCode","code","updateCartQuantity","productID","data","_restoreCodes","_publishDetailedCartChangedEvent","detailedCartChanged","_updatePrices","orderLinePrice","orderLinePrices","products","find","p","OrderLineID","formattedPrice","UnitSellingPrice","formattedLinePrice","TotalPrice","formattedDiscount","TotalDiscountAmountStr","linePrice","lineDiscount","TotalDiscountAmount","lineDiscountPercent","DiscountPercentStr","summary","totalDiscount","TotalDiscount_Value","formattedTotalDiscountInclVat","TotalDiscount","formattedTotalVAT","TotalVat","formattedTotalPrice","TotalPriceInclVat","formattedTotalPriceExclVat","TotalPriceExclVat","totalPrice","TotalPriceInclVat_Value","totalPriceExclVat","TotalPriceExclVat_Value","orderSum","freeShippingInfo","getFreeShippingData","applyCode","isCodeAlreadyEntered","enteredCodes","getEnteredCodeIds","ErrorMessage","_recalculateDiscounts","warning","combinations","DiscountInfo","let","wasCouponActivated","couponDiscount","bestCombination","isInBest","forEach","isCodeIdInCombination","AppliedCodeID","combination","IsForDelivery","codeId","isForDelivery","selected","addSessionCouponDiscount","rebuildExclusionLists","updateCombinations","getBestCombination","selectCombination","updateSessionCodesPrices","_saveCodes","getSelectedCodes","saveTempOrderCodes","applyCodes","AppliedCodes","restoreCodes"],"mappings":"OAASA,mBAAoBC,mBAAsE,KAA3C,mDAE/CC,WAAsC,KAAnB,2BAGnBC,MAA0D,KAA5C,oDAEdC,kBAAqD,KAA3B,mCACIC,qBAA2D,KAA9B,sCAE3DC,MAAiD,KAAnC,2CACdC,oBAAqD,KAAzB,iCAC5BC,eAA+C,KAAxB,gCACvBC,qBAAoD,KAAvB,8BAMzBC,uBAGTC,cACI,GAWIC,KAAAC,aAAgC,EACnCP,OAAOQ,IAAI,CACRC,eAAgB,kBAChBC,oBAAqB,4BACrBC,qBAAsB,gCACtBC,iCAAkC,yG,GAErCZ,OAAOa,IAAK,CACTJ,eAAgB,yBAChBC,oBAAqB,0BACrBC,qBAAsB,0BACtBC,iCAAkC,yF,GAGlCN,KAAAQ,OAASb,qBAAqBK,KAAKC,YAAY,EAqH/CD,KAAAS,SAAoBC,OAAOC,eAAeC,0BAC1CZ,KAAAa,iBAAmB,IAAIjB,gBACvBI,KAAAc,aAAe,IAAIxB,YACnBU,KAAAe,oBAAsB,IAAIvB,mBAC1BQ,KAAAgB,kBAA8B,GAC9BhB,KAAAiB,kBAAkDC,KAAAA,EAClDlB,KAAAmB,kBAAmDD,KAAAA,EACnDlB,KAAAoB,iBAAmB,IAAI3B,sBArJvBiB,OAAOW,aAOX,OALKvB,uBAAuBwB,YACxBxB,uBAAuBwB,SAAWtB,MAC7BuB,SAAQ,EACbvB,KAAKwB,sBAAqB,GAEvB1B,uB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BAAiBwI,iBAAgB,EAC/D5J,KAAKe,oBAAoB8I,mBAAmB7J,KAAKgB,iBAAiB,CACtE,CAEQiD,sBACJjE,KAAK2F,cAAa,EAClB3F,KAAK2J,WAAU,CACnB,CAEQnE,sBACJxF,KAAKiB,kBAAoB2B,MAAM5C,KAAKe,oBAAoB+I,WAAW9J,KAAKgB,iBAAiB,GAEpFhB,KAAKiB,kBAAkB8I,cAAiB/J,KAAKiB,kBAAkB8I,aAAavF,UAIjFxE,KAAKoB,iBAAiB4I,aAAahK,KAAKiB,iBAAiB,EACzDjB,KAAK2F,cAAa,EACtB,C,QApSS7F,sB","file":"detailed-cart-controller.js","sourcesContent":["import { cartEventPublisher, cartEventSubscriber } from \"../../common/pubsub/cart-event-pub-sub.js\";\nimport { CartItemsResultEventData, CartItemsAddedResultEventData, CartItemsRemovedResultEventData } from \"../../common/pubsub/models/cart-items-result-event-data.js\";\nimport { CartService } from \"./cart-service.js\";\nimport { IDetailedCartInfo } from \"./interfaces/detailed-cart-info.js\";\nimport { TempOrderLineProductContract } from \"./interfaces/temp-order-line-product-contract.js\";\nimport { Notify } from \"../../../components-shared/utils/notify.js\";\nimport { IDiscountCode } from \"./interfaces/discount-code.js\";\nimport { DiscountCouponsApi } from \"./discount-coupons-api.js\";\nimport { AppliedDiscountCodeInfoDtoUI, CouponDiscountsHelper } from \"./coupon-discounts-helper.js\";\nimport { ApplyCodeResult, ApplyCodesResult } from \"./interfaces/apply-code-result.js\";\nimport { Locale } from \"../../common/interfaces/locate.js\";\nimport { determineTranslation } from \"../../utils/language.js\";\nimport { FreeShippingApi } from \"./free-shipping-api.js\";\nimport { convertStringToNumber } from \"../../utils/string.js\";\n\n/// TODO: Include orderDiscount price into SummaryCartInfoContract?\n/// DiscountCoupons event to get discounts always should be called after getDetailedCartInfo to get totalDiscountSum.\n/// totalDiscountSum from getDetailedCartInfo and DiscountApplicationResultDto are not the same at the momemnt of writing this code.\n\nexport class DetailedCartController {\n private static instance: DetailedCartController;\n\n constructor() {\n if(!window.cartSettings) throw Error(\"Cart settings are not defined\");\n\n if (!DetailedCartController.instance) {\n DetailedCartController.instance = this;\n this._getData();\n this.initEventSubscibtions();\n }\n return DetailedCartController.instance;\n }\n\n /* #region Translations */\n private translations: ITranslationSet = {\n [Locale.En]:{\n couponNotFound: \"Cupon not found\",\n codeWasNotActivated: \"Discount is not activated\",\n alreadyApliedMessage: \"code has already been applied\",\n youHaveBetterDiscountCodeMessage: \"The discount code is not activated, as the products in the shopping cart already have better discounts.\"\n },\n [Locale.No]: {\n couponNotFound: \"Rabattkode ikke funnet\",\n codeWasNotActivated: \"Rabatt er ikke aktivert\",\n alreadyApliedMessage: \"koden er allerede brukt\",\n youHaveBetterDiscountCodeMessage: \"Rabattkoden er ikke aktivert, da produktene i handlekurven allerede har bedre rabatter.\"\n }\n };\n private labels = determineTranslation(this.translations) as IDetailedControllerLabels;\n /* #endregion */\n\n /* #region Public */\n public initEventSubscibtions(){\n cartEventSubscriber.onCartItemsAdded(this._onCartItemsAdded.bind(this));\n cartEventSubscriber.onCartItemsRemoved(this._onCartItemsRemoved.bind(this));\n cartEventSubscriber.onCartEmptied(this._onCartEmptied.bind(this));\n cartEventSubscriber.onCartQuantityUpdated(this._onCartQuantityUpdated.bind(this));\n }\n\n public getDetailedCartInfo(): IDetailedCartInfo{\n return this._detailedCartInfo;\n }\n\n public countSingles(line: TempOrderLineProductContract){\n return line.quantity % line.factor;\n }\n\n public countPackages(line: TempOrderLineProductContract){\n return Math.floor(line.quantity / line.factor);\n }\n\n public async removeLine(line: TempOrderLineProductContract){\n try{\n await this._cartService.removeFromCart(line.tempOrderLineID);\n } catch(error) {\n new Notify().success(`Remove orderline error`);\n console.error('Remove orderline error', error);\n }\n }\n\n public async clearCart(){\n try{\n await this._cartService.emptyCart();\n } catch(error) {\n new Notify().success(`Clear cart failed`);\n console.error('Clear cart failed', error);\n }\n }\n\n public async updateQuantity(quantity: number, line: TempOrderLineProductContract){\n line.quantity = quantity;\n this._updateCartLine(line);\n }\n\n public async onFactorInputChange(quantity: number, line: TempOrderLineProductContract){\n const oldPackageQuantity = this.countPackages(line);\n const newPackageQuantity = quantity;\n const packagesDifference = newPackageQuantity - oldPackageQuantity;\n line.quantity = Number(line.quantity + line.factor * packagesDifference);\n this._updateCartLine(line);\n }\n\n public async onFractionInputChange(quantity: number, line: TempOrderLineProductContract){\n const oldSinglesQuantity = this.countSingles(line);\n const newSinglesQuantity = quantity;\n const singlesDifference = newSinglesQuantity - oldSinglesQuantity;\n line.quantity = Number(line.quantity + singlesDifference);\n this._updateCartLine(line);\n }\n\n public async createOffer() { //Feature for admin users only\n await this._cartService.createOffer();\n }\n\n /* #region Discounts */\n public getSessionCouponDiscounts(): AppliedDiscountCodeInfoDtoUI[]{\n return this._couponDiscounts.sessionCouponDiscounts;\n }\n\n public selectDiscount(codeID: number): void {\n this._couponDiscounts.selectCouponDiscount(codeID);\n this._updateStates();\n }\n\n public unselectDiscount(codeID: number): void {\n this._couponDiscounts.unselectCouponDiscount(codeID);\n this._updateStates();\n }\n\n public getOrderDiscountVisibility(): boolean{\n const appliedDiscountInfo = this._couponDiscounts.getSelectedCombination();\n\n if(!appliedDiscountInfo) {\n return true;\n }\n\n if(appliedDiscountInfo.codesInfo.length === 0){ \n return true; \n }\n\n return appliedDiscountInfo.orderPrice.generalOrderDiscounts.length > 0;\n }\n /* #endregion */\n\n /* #endregion */\n\n /* #region Event handlers */\n private async _onCartQuantityUpdated(topic: string, eventData: CartItemsResultEventData){\n await this._updateDetailedCartInfo(eventData.result.detailedCartInfo);\n }\n\n private async _onCartItemsAdded(topic: string, eventData: CartItemsAddedResultEventData){\n await this._updateDetailedCartInfo(eventData.result.detailedCartInfo);\n }\n\n private async _onCartItemsRemoved(topic: string, eventData: CartItemsRemovedResultEventData){\n await this._updateDetailedCartInfo(eventData.result.detailedCartInfo);\n }\n\n private async _onCartEmptied(topic: string, eventData: CartItemsRemovedResultEventData){\n await this._updateDetailedCartInfo(eventData.result.detailedCartInfo);\n }\n /* #endregion */\n\n /* #region Private */\n private _inclVat: boolean = window.globalSettings.displayPricesIncludingVat;\n private _freeShipipngApi = new FreeShippingApi();\n private _cartService = new CartService();\n private _discountCouponsApi = new DiscountCouponsApi();\n private _appliedCodesName: string[] = [];\n private _applyCodesResult: ApplyCodesResult | undefined = undefined;\n private _detailedCartInfo: IDetailedCartInfo | undefined = undefined;\n private _couponDiscounts = new CouponDiscountsHelper();\n\n private _getData(): void{\n this._cartService.detailedCartInfo()\n .then((detailedCartInfo) => {\n this._appliedCodesName = detailedCartInfo.couponCodes?.map((discountCode: IDiscountCode) => discountCode.code) || [];\n this._updateDetailedCartInfo(detailedCartInfo);\n })\n }\n\n private async _updateCartLine(line: TempOrderLineProductContract){\n this._cartService.updateCartQuantity(line.tempOrderLineID, line.quantity, line.productID);\n }\n\n private async _updateDetailedCartInfo(data: IDetailedCartInfo) {\n this._detailedCartInfo = data;\n await this._restoreCodes();\n }\n\n /* #region Discount */\n private _publishDetailedCartChangedEvent() {\n cartEventPublisher.detailedCartChanged(this._detailedCartInfo);\n }\n\n private async _updatePrices() {\n const appliedDiscountInfo = this._couponDiscounts.getSelectedCombination();\n\n if (!appliedDiscountInfo) {\n return;\n }\n\n //Update order lines\n for (const orderLinePrice of appliedDiscountInfo.orderLinePrices) {\n this._detailedCartInfo.products.find(p => {\n if(p.tempOrderLineID === orderLinePrice.OrderLineID){\n p.formattedPrice = orderLinePrice.UnitSellingPrice;\n p.formattedLinePrice = orderLinePrice.TotalPrice;\n p.formattedDiscount = orderLinePrice.TotalDiscountAmountStr;\n p.linePrice = convertStringToNumber(orderLinePrice.TotalPrice); //is used in the order-line.ts condition private _showPricePerUnit: boolean = this.orderLine.linePrice > 0\n p.lineDiscount = orderLinePrice.TotalDiscountAmount;\n p.lineDiscountPercent = convertStringToNumber(orderLinePrice.DiscountPercentStr); //convertStringToNumber can be removed when we get propper price format from the server\n }\n });\n }\n\n //Update cart summary\n this._detailedCartInfo.summary.totalDiscount = appliedDiscountInfo.orderPrice.TotalDiscount_Value;\n this._detailedCartInfo.summary.formattedTotalDiscountInclVat = appliedDiscountInfo.orderPrice.TotalDiscount;\n this._detailedCartInfo.summary.formattedTotalVAT = appliedDiscountInfo.orderPrice.TotalVat;\n this._detailedCartInfo.summary.formattedTotalPrice = appliedDiscountInfo.orderPrice.TotalPriceInclVat;\n this._detailedCartInfo.summary.formattedTotalPriceExclVat = appliedDiscountInfo.orderPrice.TotalPriceExclVat;\n this._detailedCartInfo.summary.totalPrice = appliedDiscountInfo.orderPrice.TotalPriceInclVat_Value;\n this._detailedCartInfo.summary.totalPriceExclVat = appliedDiscountInfo.orderPrice.TotalPriceExclVat_Value;\n\n const orderSum = this._inclVat ? this._detailedCartInfo.summary.totalPrice : this._detailedCartInfo.summary.totalPriceExclVat\n this._detailedCartInfo.freeShippingInfo = await this._freeShipipngApi.getFreeShippingData(orderSum); //TODO: to use this record and avoid an extra request to FreeShippingApi - we need get propper prices from the server at freeshippinginfo contract (inclVat or/and exclVat).\n\n this._publishDetailedCartChangedEvent();\n }\n\n public async applyCode(code:string): Promise{\n if (this._couponDiscounts.isCodeAlreadyEntered(code)) {\n new Notify().success(`\"${code}\" - ${this.labels.alreadyApliedMessage}`);\n return;\n }\n\n const enteredCodes = this._couponDiscounts.getEnteredCodeIds();\n const result = await this._discountCouponsApi.applyCode(code, enteredCodes);\n\n if (result.ErrorMessage) {\n new Notify().warning(`\"${code}\" - ${result.ErrorMessage}`);\n return;\n }\n\n this._recalculateDiscounts(result, code);\n\n return result;\n }\n\n private async _recalculateDiscounts(result: ApplyCodeResult, code: string) {\n this._couponDiscounts.combinations = result.DiscountInfo;\n\n let wasCouponActivated = false;\n (this._couponDiscounts.combinations).forEach((combination) => {\n if (this._couponDiscounts.isCodeIdInCombination(result.AppliedCodeID, combination)) {\n wasCouponActivated = true;\n }\n });\n\n if (!wasCouponActivated && !result.IsForDelivery) {\n new Notify().warning(this.labels.codeWasNotActivated);\n return;\n }\n\n const couponDiscount = {\n codeId: result.AppliedCodeID,\n code: code,\n isForDelivery: result.IsForDelivery,\n selected: true,\n } as AppliedDiscountCodeInfoDtoUI;\n\n this._couponDiscounts.addSessionCouponDiscount(couponDiscount);\n this._couponDiscounts.rebuildExclusionLists();\n this._couponDiscounts.updateCombinations(result.DiscountInfo);\n\n const bestCombination = this._couponDiscounts.getBestCombination();\n const isInBest = this._couponDiscounts.isCodeIdInCombination(couponDiscount.codeId, bestCombination);\n\n this._couponDiscounts.selectCombination(bestCombination);\n this._couponDiscounts.updateSessionCodesPrices();\n\n this._updateStates();\n\n if (!isInBest) {\n if (!couponDiscount.isForDelivery){\n new Notify().warning(this.labels.youHaveBetterDiscountCodeMessage);\n }\n }\n }\n\n private _saveCodes(): void{\n this._appliedCodesName = this._couponDiscounts.getSelectedCodes();\n this._discountCouponsApi.saveTempOrderCodes(this._appliedCodesName);\n }\n\n private async _updateStates(){\n this._updatePrices();\n this._saveCodes();\n }\n\n private async _restoreCodes(){\n this._applyCodesResult = await this._discountCouponsApi.applyCodes(this._appliedCodesName);\n\n if (!this._applyCodesResult.AppliedCodes && !this._applyCodesResult.AppliedCodes.length) {\n return;\n }\n\n this._couponDiscounts.restoreCodes(this._applyCodesResult);\n this._updatePrices();\n }\n /* #endregion */\n\n /* #endregion */\n}\n\n/* #region Local interfaces */\ninterface IDetailedControllerLabels{\n couponNotFound: string,\n alreadyApliedMessage: string,\n codeWasNotActivated: string,\n youHaveBetterDiscountCodeMessage: string\n}\n\ninterface ITranslationSet {\n [key:string]: IDetailedControllerLabels\n}\n/* #endregion */"]}