UNPKG

@spartacus/checkout

Version:

Checkout feature library for Spartacus

876 lines (861 loc) 220 kB
import * as i3$2 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { Injectable, Component, NgModule, ChangeDetectionStrategy, isDevMode, Pipe, EventEmitter, Input, Output, ViewChild } from '@angular/core'; import * as i3$1 from '@angular/forms'; import { Validators, FormsModule, ReactiveFormsModule } from '@angular/forms'; import * as i1 from '@spartacus/core'; import { I18nModule, provideDefaultConfig, B2BUserRole, GlobalMessageType, OCC_USER_ID_ANONYMOUS, OCC_USER_ID_GUEST, EMAIL_PATTERN, UrlModule, ConfigModule, isNotUndefined, B2BPaymentTypeEnum, DaysOfWeek, recurrencePeriod, ORDER_TYPE, provideConfig, PromotionLocation, FeaturesConfigModule } from '@spartacus/core'; import * as i4 from '@spartacus/storefront'; import { CustomFormValidators, FormErrorsModule, CartSharedModule, CartValidationGuard, SpinnerModule, ICON_TYPE, SuggestedAddressDialogComponent, CardModule, IconModule, SpinnerComponent, DIALOG_TYPE, PromotionsModule, AddressFormModule, PwaModule, OrderOverviewModule } from '@spartacus/storefront'; import { map, filter, tap, shareReplay, switchMap, skipWhile, debounceTime, distinctUntilChanged, take, withLatestFrom, takeWhile } from 'rxjs/operators'; import * as i3 from '@angular/router'; import { RouterModule } from '@angular/router'; import { combineLatest, of, BehaviorSubject, Subscription } from 'rxjs'; import * as i1$1 from '@spartacus/checkout/root'; import { DeliveryModePreferences, CheckoutStepType, checkoutShippingSteps, checkoutPaymentSteps } from '@spartacus/checkout/root'; import * as i4$1 from '@spartacus/user/account/root'; import * as i5 from '@ng-select/ng-select'; import { NgSelectModule } from '@ng-select/ng-select'; import * as i1$2 from '@spartacus/user/profile/root'; class NotCheckoutAuthGuard { constructor(authService, activeCartService, semanticPathService, router) { this.authService = authService; this.activeCartService = activeCartService; this.semanticPathService = semanticPathService; this.router = router; } canActivate() { return this.authService.isUserLoggedIn().pipe(map((isLoggedIn) => { if (isLoggedIn) { return this.router.parseUrl(this.semanticPathService.get('home')); } else if (this.activeCartService.isGuestCart()) { return this.router.parseUrl(this.semanticPathService.get('cart')); } return !isLoggedIn; })); } } NotCheckoutAuthGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: NotCheckoutAuthGuard, deps: [{ token: i1.AuthService }, { token: i1.ActiveCartService }, { token: i1.SemanticPathService }, { token: i3.Router }], target: i0.ɵɵFactoryTarget.Injectable }); NotCheckoutAuthGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: NotCheckoutAuthGuard, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: NotCheckoutAuthGuard, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: i1.AuthService }, { type: i1.ActiveCartService }, { type: i1.SemanticPathService }, { type: i3.Router }]; } }); class CheckoutLoginComponent { constructor(formBuilder, authRedirectService, activeCartService) { this.formBuilder = formBuilder; this.authRedirectService = authRedirectService; this.activeCartService = activeCartService; this.checkoutLoginForm = this.formBuilder.group({ email: ['', [Validators.required, CustomFormValidators.emailValidator]], emailConfirmation: ['', [Validators.required]], }, { validators: CustomFormValidators.emailsMustMatch('email', 'emailConfirmation'), }); } onSubmit() { var _a; if (this.checkoutLoginForm.valid) { const email = (_a = this.checkoutLoginForm.get('email')) === null || _a === void 0 ? void 0 : _a.value; this.activeCartService.addEmail(email); if (!this.sub) { this.sub = this.activeCartService.getAssignedUser().subscribe(() => { if (this.activeCartService.isGuestCart()) { this.authRedirectService.redirect(); } }); } } else { this.checkoutLoginForm.markAllAsTouched(); } } ngOnDestroy() { if (this.sub) { this.sub.unsubscribe(); } } } CheckoutLoginComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutLoginComponent, deps: [{ token: i3$1.FormBuilder }, { token: i1.AuthRedirectService }, { token: i1.ActiveCartService }], target: i0.ɵɵFactoryTarget.Component }); CheckoutLoginComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: CheckoutLoginComponent, selector: "cx-checkout-login", ngImport: i0, template: "<form (ngSubmit)=\"onSubmit()\" [formGroup]=\"checkoutLoginForm\">\n <div class=\"form-group\">\n <label>\n <span class=\"label-content\">{{\n 'checkoutLogin.emailAddress.label' | cxTranslate\n }}</span>\n <input\n aria-required=\"true\"\n type=\"email\"\n name=\"email\"\n class=\"form-control\"\n formControlName=\"email\"\n placeholder=\"{{\n 'checkoutLogin.emailAddress.placeholder' | cxTranslate\n }}\"\n />\n <cx-form-errors\n aria-live=\"assertive\"\n aria-atomic=\"true\"\n [control]=\"checkoutLoginForm.get('email')\"\n ></cx-form-errors>\n </label>\n </div>\n\n <div class=\"form-group\">\n <label>\n <span class=\"label-content\">{{\n 'checkoutLogin.confirmEmail.label' | cxTranslate\n }}</span>\n <input\n aria-required=\"true\"\n type=\"email\"\n name=\"emailConfirmation\"\n class=\"form-control\"\n formControlName=\"emailConfirmation\"\n placeholder=\"{{\n 'checkoutLogin.confirmEmail.placeholder' | cxTranslate\n }}\"\n />\n <cx-form-errors\n aria-live=\"assertive\"\n aria-atomic=\"true\"\n [control]=\"checkoutLoginForm.get('emailConfirmation')\"\n ></cx-form-errors>\n </label>\n </div>\n\n <button type=\"submit\" class=\"btn btn-block btn-primary\">\n {{ 'checkoutLogin.continue' | cxTranslate }}\n </button>\n</form>\n", components: [{ type: i4.FormErrorsComponent, selector: "cx-form-errors", inputs: ["prefix", "translationParams", "control"] }], directives: [{ type: i3$1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { type: i3$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i3$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i3$1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i3$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i3$1.FormControlName, selector: "[formControlName]", inputs: ["disabled", "formControlName", "ngModel"], outputs: ["ngModelChange"] }], pipes: { "cxTranslate": i1.TranslatePipe } }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutLoginComponent, decorators: [{ type: Component, args: [{ selector: 'cx-checkout-login', templateUrl: './checkout-login.component.html', }] }], ctorParameters: function () { return [{ type: i3$1.FormBuilder }, { type: i1.AuthRedirectService }, { type: i1.ActiveCartService }]; } }); class CheckoutLoginModule { } CheckoutLoginModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutLoginModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); CheckoutLoginModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutLoginModule, declarations: [CheckoutLoginComponent], imports: [CommonModule, I18nModule, FormsModule, ReactiveFormsModule, FormsModule, ReactiveFormsModule, FormErrorsModule], exports: [CheckoutLoginComponent] }); CheckoutLoginModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutLoginModule, providers: [ provideDefaultConfig({ cmsComponents: { GuestCheckoutLoginComponent: { component: CheckoutLoginComponent, guards: [NotCheckoutAuthGuard], }, }, }), ], imports: [[ CommonModule, I18nModule, FormsModule, ReactiveFormsModule, FormsModule, ReactiveFormsModule, FormErrorsModule, ]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutLoginModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule, I18nModule, FormsModule, ReactiveFormsModule, FormsModule, ReactiveFormsModule, FormErrorsModule, ], providers: [ provideDefaultConfig({ cmsComponents: { GuestCheckoutLoginComponent: { component: CheckoutLoginComponent, guards: [NotCheckoutAuthGuard], }, }, }), ], declarations: [CheckoutLoginComponent], exports: [CheckoutLoginComponent], }] }] }); class CartNotEmptyGuard { constructor(activeCartService, semanticPathService, router) { this.activeCartService = activeCartService; this.semanticPathService = semanticPathService; this.router = router; } canActivate() { return combineLatest([ this.activeCartService.getActive(), this.activeCartService.isStable(), ]).pipe(filter(([_, loaded]) => loaded), map(([cart]) => { if (this.isEmpty(cart)) { return this.router.parseUrl(this.semanticPathService.get('home')); } return true; })); } isEmpty(cart) { return cart && !cart.totalItems; } } CartNotEmptyGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CartNotEmptyGuard, deps: [{ token: i1.ActiveCartService }, { token: i1.SemanticPathService }, { token: i3.Router }], target: i0.ɵɵFactoryTarget.Injectable }); CartNotEmptyGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CartNotEmptyGuard, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CartNotEmptyGuard, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: i1.ActiveCartService }, { type: i1.SemanticPathService }, { type: i3.Router }]; } }); class CheckoutConfigService { constructor(checkoutConfig) { var _a, _b, _c, _d, _e; this.checkoutConfig = checkoutConfig; this.express = (_b = (_a = this.checkoutConfig.checkout) === null || _a === void 0 ? void 0 : _a.express) !== null && _b !== void 0 ? _b : false; this.guest = (_d = (_c = this.checkoutConfig.checkout) === null || _c === void 0 ? void 0 : _c.guest) !== null && _d !== void 0 ? _d : false; this.defaultDeliveryMode = ((_e = this.checkoutConfig.checkout) === null || _e === void 0 ? void 0 : _e.defaultDeliveryMode) || []; } compareDeliveryCost(deliveryMode1, deliveryMode2) { var _a, _b; if (((_a = deliveryMode1.deliveryCost) === null || _a === void 0 ? void 0 : _a.value) && ((_b = deliveryMode2.deliveryCost) === null || _b === void 0 ? void 0 : _b.value)) { if (deliveryMode1.deliveryCost.value > deliveryMode2.deliveryCost.value) { return 1; } else if (deliveryMode1.deliveryCost.value < deliveryMode2.deliveryCost.value) { return -1; } } return 0; } findMatchingDeliveryMode(deliveryModes, index = 0) { var _a; switch (this.defaultDeliveryMode[index]) { case DeliveryModePreferences.FREE: if (((_a = deliveryModes[0].deliveryCost) === null || _a === void 0 ? void 0 : _a.value) === 0) { return deliveryModes[0].code; } break; case DeliveryModePreferences.LEAST_EXPENSIVE: const leastExpensiveFound = deliveryModes.find((deliveryMode) => { var _a; return ((_a = deliveryMode.deliveryCost) === null || _a === void 0 ? void 0 : _a.value) !== 0; }); if (leastExpensiveFound) { return leastExpensiveFound.code; } break; case DeliveryModePreferences.MOST_EXPENSIVE: return deliveryModes[deliveryModes.length - 1].code; default: const codeFound = deliveryModes.find((deliveryMode) => deliveryMode.code === this.defaultDeliveryMode[index]); if (codeFound) { return codeFound.code; } } const lastMode = this.defaultDeliveryMode.length - 1 <= index; return lastMode ? deliveryModes[0].code : this.findMatchingDeliveryMode(deliveryModes, index + 1); } getPreferredDeliveryMode(deliveryModes) { deliveryModes.sort(this.compareDeliveryCost); return this.findMatchingDeliveryMode(deliveryModes); } isExpressCheckout() { return this.express; } isGuestCheckout() { return this.guest; } } CheckoutConfigService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutConfigService, deps: [{ token: i1$1.CheckoutConfig }], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutConfigService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutConfigService, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutConfigService, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: i1$1.CheckoutConfig }]; } }); class CheckoutAuthGuard { constructor(authService, authRedirectService, checkoutConfigService, activeCartService, semanticPathService, router, userService, globalMessageService) { this.authService = authService; this.authRedirectService = authRedirectService; this.checkoutConfigService = checkoutConfigService; this.activeCartService = activeCartService; this.semanticPathService = semanticPathService; this.router = router; this.userService = userService; this.globalMessageService = globalMessageService; } canActivate() { return combineLatest([ this.authService.isUserLoggedIn(), this.activeCartService.getAssignedUser(), this.userService.get(), this.activeCartService.isStable(), ]).pipe(filter(([, , _user, isStable]) => isStable), // if the user is authenticated and we have their data, OR if the user is anonymous filter(([isLoggedIn, , user]) => (!!user && isLoggedIn) || !isLoggedIn), map(([isLoggedIn, cartUser, user]) => { if (!isLoggedIn) { return this.handleAnonymousUser(cartUser); } else if (user && 'roles' in user) { return this.handleUserRole(user); } return isLoggedIn; })); } handleAnonymousUser(cartUser) { if (this.activeCartService.isGuestCart()) { return !!cartUser; } this.authRedirectService.saveCurrentNavigationUrl(); if (this.checkoutConfigService.isGuestCheckout()) { return this.router.createUrlTree([this.semanticPathService.get('login')], { queryParams: { forced: true } }); } else { return this.router.parseUrl(this.semanticPathService.get('login')); } } handleUserRole(user) { const roles = user.roles; if (roles === null || roles === void 0 ? void 0 : roles.includes(B2BUserRole.CUSTOMER)) { return true; } this.globalMessageService.add({ key: 'checkout.invalid.accountType' }, GlobalMessageType.MSG_TYPE_WARNING); return this.router.parseUrl(this.semanticPathService.get('home')); } } CheckoutAuthGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutAuthGuard, deps: [{ token: i1.AuthService }, { token: i1.AuthRedirectService }, { token: CheckoutConfigService }, { token: i1.ActiveCartService }, { token: i1.SemanticPathService }, { token: i3.Router }, { token: i4$1.UserAccountFacade }, { token: i1.GlobalMessageService }], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutAuthGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutAuthGuard, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutAuthGuard, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: i1.AuthService }, { type: i1.AuthRedirectService }, { type: CheckoutConfigService }, { type: i1.ActiveCartService }, { type: i1.SemanticPathService }, { type: i3.Router }, { type: i4$1.UserAccountFacade }, { type: i1.GlobalMessageService }]; } }); class CheckoutDetailsService { constructor(checkoutService, checkoutDeliveryService, checkoutPaymentService, activeCartService) { this.checkoutService = checkoutService; this.checkoutDeliveryService = checkoutDeliveryService; this.checkoutPaymentService = checkoutPaymentService; this.activeCartService = activeCartService; this.cartId$ = combineLatest([ this.activeCartService.getActive(), this.activeCartService.isStable(), ]).pipe(filter(([, isStable]) => isStable), map(([cartData]) => { var _a; const cartUser = cartData.user; if (cartUser && (cartUser.uid === OCC_USER_ID_ANONYMOUS || cartUser.uid === OCC_USER_ID_GUEST || !!((_a = cartUser.uid) === null || _a === void 0 ? void 0 : _a.split('|').slice(1).join('|').match(EMAIL_PATTERN)))) { return cartData.guid; } return cartData.code; }), filter((cartId) => !!cartId)); this.getCheckoutDetailsLoaded$ = this.cartId$.pipe(tap((cartId) => this.checkoutService.loadCheckoutDetails(cartId)), shareReplay(1), switchMap(() => this.checkoutService.getCheckoutDetailsLoaded()), skipWhile((loaded) => !loaded)); } getDeliveryAddress() { return this.getCheckoutDetailsLoaded$.pipe(switchMap(() => this.checkoutDeliveryService.getDeliveryAddress())); } getSelectedDeliveryModeCode() { return this.getCheckoutDetailsLoaded$.pipe(switchMap(() => this.checkoutDeliveryService.getSelectedDeliveryModeCode())); } getPaymentDetails() { return this.getCheckoutDetailsLoaded$.pipe(switchMap(() => this.checkoutPaymentService.getPaymentDetails())); } } CheckoutDetailsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutDetailsService, deps: [{ token: i1$1.CheckoutFacade }, { token: i1$1.CheckoutDeliveryFacade }, { token: i1$1.CheckoutPaymentFacade }, { token: i1.ActiveCartService }], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutDetailsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutDetailsService, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutDetailsService, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: i1$1.CheckoutFacade }, { type: i1$1.CheckoutDeliveryFacade }, { type: i1$1.CheckoutPaymentFacade }, { type: i1.ActiveCartService }]; } }); class ExpressCheckoutService { constructor(userAddressService, userPaymentService, checkoutDeliveryService, checkoutPaymentService, checkoutDetailsService, checkoutConfigService, clearCheckoutService) { this.userAddressService = userAddressService; this.userPaymentService = userPaymentService; this.checkoutDeliveryService = checkoutDeliveryService; this.checkoutPaymentService = checkoutPaymentService; this.checkoutDetailsService = checkoutDetailsService; this.checkoutConfigService = checkoutConfigService; this.clearCheckoutService = clearCheckoutService; this.setShippingAddress(); this.setDeliveryMode(); this.setPaymentMethod(); } setShippingAddress() { this.shippingAddressSet$ = combineLatest([ this.userAddressService.getAddresses(), this.userAddressService.getAddressesLoadedSuccess(), this.checkoutDeliveryService.getSetDeliveryAddressProcess(), ]).pipe(debounceTime(0), tap(([, addressesLoadedSuccess]) => { if (!addressesLoadedSuccess) { this.userAddressService.loadAddresses(); } }), filter(([, addressesLoadedSuccess]) => addressesLoadedSuccess), switchMap(([addresses, , setDeliveryAddressProcess]) => { const defaultAddress = addresses.find((address) => address.defaultAddress) || addresses[0]; if (defaultAddress && Object.keys(defaultAddress).length) { if (!(setDeliveryAddressProcess.success || setDeliveryAddressProcess.error || setDeliveryAddressProcess.loading)) { this.checkoutDeliveryService.setDeliveryAddress(defaultAddress); } return of(setDeliveryAddressProcess).pipe(filter((setDeliveryAddressProcessState) => { var _a; return ((_a = ((setDeliveryAddressProcessState.success || setDeliveryAddressProcessState.error) && !setDeliveryAddressProcessState.loading)) !== null && _a !== void 0 ? _a : false); }), switchMap((setDeliveryAddressProcessState) => { if (setDeliveryAddressProcessState.success) { return this.checkoutDetailsService.getDeliveryAddress(); } return of(false); }), map((data) => Boolean(data && Object.keys(data).length))); } return of(false); }), distinctUntilChanged()); } setPaymentMethod() { this.paymentMethodSet$ = combineLatest([ this.deliveryModeSet$, this.userPaymentService.getPaymentMethods(), this.userPaymentService.getPaymentMethodsLoadedSuccess(), this.checkoutPaymentService.getSetPaymentDetailsResultProcess(), ]).pipe(debounceTime(0), tap(([, , paymentMethodsLoadedSuccess]) => { if (!paymentMethodsLoadedSuccess) { this.userPaymentService.loadPaymentMethods(); } }), filter(([, , success]) => success), switchMap(([deliveryModeSet, payments, , setPaymentDetailsProcess]) => { if (!deliveryModeSet) { return of(false); } const defaultPayment = payments.find((address) => address.defaultPayment) || payments[0]; if (defaultPayment && Object.keys(defaultPayment).length) { if (!(setPaymentDetailsProcess.success || setPaymentDetailsProcess.error || setPaymentDetailsProcess.loading)) { this.checkoutPaymentService.setPaymentDetails(defaultPayment); } return of(setPaymentDetailsProcess).pipe(filter((setPaymentDetailsProcessState) => { var _a; return ((_a = ((setPaymentDetailsProcessState.success || setPaymentDetailsProcessState.error) && !setPaymentDetailsProcessState.loading)) !== null && _a !== void 0 ? _a : false); }), switchMap((setPaymentDetailsProcessState) => { if (setPaymentDetailsProcessState.success) { return this.checkoutDetailsService.getPaymentDetails(); } return of(false); }), map((data) => Boolean(data && Object.keys(data).length))); } return of(false); })); } setDeliveryMode() { this.deliveryModeSet$ = combineLatest([ this.shippingAddressSet$, this.checkoutDeliveryService.getSupportedDeliveryModes(), this.checkoutDeliveryService.getSetDeliveryModeProcess(), this.checkoutDeliveryService.getLoadSupportedDeliveryModeProcess(), ]).pipe(debounceTime(0), switchMap(([addressSet, supportedDeliveryModes, setDeliveryModeStatusFlag, loadSupportedDeliveryModeStatus,]) => { if (addressSet) { return of([ supportedDeliveryModes, setDeliveryModeStatusFlag, loadSupportedDeliveryModeStatus, ]).pipe(filter(([, , supportedDeliveryModeStatus]) => { var _a; return (_a = supportedDeliveryModeStatus.success) !== null && _a !== void 0 ? _a : false; }), switchMap(([deliveryModes, setDeliveryModeStatus, ,]) => { if (Boolean(deliveryModes.length)) { const preferredDeliveryMode = this.checkoutConfigService.getPreferredDeliveryMode(deliveryModes); return of([ preferredDeliveryMode, setDeliveryModeStatus, ]).pipe(tap(([deliveryMode, deliveryModeLoadingStatus]) => { if (deliveryMode && !(deliveryModeLoadingStatus.success || deliveryModeLoadingStatus.error || deliveryModeLoadingStatus.loading)) { this.checkoutDeliveryService.setDeliveryMode(deliveryMode); } }), filter(([, deliveryModeLoadingStatus]) => { var _a; return ((_a = ((deliveryModeLoadingStatus.success || deliveryModeLoadingStatus.error) && !deliveryModeLoadingStatus.loading)) !== null && _a !== void 0 ? _a : false); }), switchMap(([, deliveryModeLoadingStatus]) => { if (deliveryModeLoadingStatus.success) { return this.checkoutDetailsService.getSelectedDeliveryModeCode(); } return of(false); }), map((data) => Boolean(data))); } return of(false); })); } else { return of(false); } }), distinctUntilChanged()); } trySetDefaultCheckoutDetails() { this.clearCheckoutService.resetCheckoutProcesses(); return this.paymentMethodSet$.pipe(map((paymentMethodSet) => Boolean(paymentMethodSet))); } } ExpressCheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: ExpressCheckoutService, deps: [{ token: i1.UserAddressService }, { token: i1.UserPaymentService }, { token: i1$1.CheckoutDeliveryFacade }, { token: i1$1.CheckoutPaymentFacade }, { token: CheckoutDetailsService }, { token: CheckoutConfigService }, { token: i1$1.ClearCheckoutFacade }], target: i0.ɵɵFactoryTarget.Injectable }); ExpressCheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: ExpressCheckoutService, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: ExpressCheckoutService, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: i1.UserAddressService }, { type: i1.UserPaymentService }, { type: i1$1.CheckoutDeliveryFacade }, { type: i1$1.CheckoutPaymentFacade }, { type: CheckoutDetailsService }, { type: CheckoutConfigService }, { type: i1$1.ClearCheckoutFacade }]; } }); class CheckoutStepService { constructor(routingService, checkoutConfig, routingConfigService) { this.routingService = routingService; this.checkoutConfig = checkoutConfig; this.routingConfigService = routingConfigService; this.steps$ = new BehaviorSubject([]); this.activeStepIndex$ = this.routingService .getRouterState() .pipe(switchMap((router) => { const activeStepUrl = router.state.context.id; return this.steps$.pipe(map((steps) => { let activeIndex = 0; steps.forEach((step, index) => { var _a; const routeUrl = `/${(_a = this.routingConfigService.getRouteConfig(step.routeName) .paths) === null || _a === void 0 ? void 0 : _a[0]}`; if (routeUrl === activeStepUrl) { activeIndex = index; } }); return activeIndex; })); })); this.resetSteps(); } back(activatedRoute) { const previousUrl = this.getPreviousCheckoutStepUrl(activatedRoute); this.routingService.go(previousUrl === null ? 'cart' : previousUrl); } next(activatedRoute) { const nextUrl = this.getNextCheckoutStepUrl(activatedRoute); this.routingService.go(nextUrl); } goToStepWithIndex(stepIndex) { this.routingService.go(this.getStepUrlFromStepRoute(this.allSteps[stepIndex].routeName)); } getBackBntText(activatedRoute) { if (this.getPreviousCheckoutStepUrl(activatedRoute) === null) { return 'checkout.backToCart'; } return 'common.back'; } resetSteps() { var _a, _b; this.allSteps = ((_b = (_a = this.checkoutConfig.checkout) === null || _a === void 0 ? void 0 : _a.steps) !== null && _b !== void 0 ? _b : []) .filter((step) => !step.disabled) .map((x) => Object.assign({}, x)); this.steps$.next(this.allSteps); } disableEnableStep(currentStepType, disabled) { const currentStep = this.allSteps.find((step) => step.type.includes(currentStepType)); if (currentStep && currentStep.disabled !== disabled) { currentStep.disabled = disabled; this.steps$.next(this.allSteps.filter((step) => !step.disabled)); } } getCheckoutStep(currentStepType) { const index = this.getCheckoutStepIndex('type', currentStepType); if (index !== null) { return this.allSteps[index]; } } getCheckoutStepRoute(currentStepType) { var _a; return (_a = this.getCheckoutStep(currentStepType)) === null || _a === void 0 ? void 0 : _a.routeName; } getFirstCheckoutStepRoute() { return this.allSteps[0].routeName; } getNextCheckoutStepUrl(activatedRoute) { const stepIndex = this.getCurrentStepIndex(activatedRoute); if (stepIndex !== null && stepIndex >= 0) { let i = 1; while (this.allSteps[stepIndex + i] && this.allSteps[stepIndex + i].disabled) { i++; } const nextStep = this.allSteps[stepIndex + i]; if (nextStep) { return this.getStepUrlFromStepRoute(nextStep.routeName); } } return null; } getPreviousCheckoutStepUrl(activatedRoute) { const stepIndex = this.getCurrentStepIndex(activatedRoute); if (stepIndex !== null && stepIndex >= 0) { let i = 1; while (this.allSteps[stepIndex - i] && this.allSteps[stepIndex - i].disabled) { i++; } const previousStep = this.allSteps[stepIndex - i]; if (previousStep) { return this.getStepUrlFromStepRoute(previousStep.routeName); } } return null; } getCurrentStepIndex(activatedRoute) { const currentStepUrl = this.getStepUrlFromActivatedRoute(activatedRoute); const stepIndex = this.allSteps.findIndex((step) => currentStepUrl === `/${this.getStepUrlFromStepRoute(step.routeName)}`); return stepIndex === -1 ? null : stepIndex; } getStepUrlFromActivatedRoute(activatedRoute) { return activatedRoute && activatedRoute.snapshot && activatedRoute.snapshot.url ? `/${activatedRoute.snapshot.url.join('/')}` : null; } getStepUrlFromStepRoute(stepRoute) { var _a, _b; return ((_b = (_a = this.routingConfigService.getRouteConfig(stepRoute).paths) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : null); } getCheckoutStepIndex(key, value) { return key && value ? this.allSteps.findIndex((step) => { const propertyVal = step[key]; return propertyVal instanceof Array ? propertyVal.includes(value) : propertyVal === value; }) : null; } } CheckoutStepService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutStepService, deps: [{ token: i1.RoutingService }, { token: i1$1.CheckoutConfig }, { token: i1.RoutingConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutStepService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutStepService, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutStepService, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: i1.RoutingService }, { type: i1$1.CheckoutConfig }, { type: i1.RoutingConfigService }]; } }); class CheckoutGuard { constructor(router, routingConfigService, checkoutConfigService, expressCheckoutService, activeCartService, checkoutStepService) { var _a; this.router = router; this.routingConfigService = routingConfigService; this.checkoutConfigService = checkoutConfigService; this.expressCheckoutService = expressCheckoutService; this.activeCartService = activeCartService; this.checkoutStepService = checkoutStepService; this.firstStep$ = of(this.router.parseUrl((_a = this.routingConfigService.getRouteConfig(this.checkoutStepService.getFirstCheckoutStepRoute()).paths) === null || _a === void 0 ? void 0 : _a[0])); } canActivate() { if (this.checkoutConfigService.isExpressCheckout() && !this.activeCartService.isGuestCart()) { return this.expressCheckoutService.trySetDefaultCheckoutDetails().pipe(switchMap((expressCheckoutPossible) => { var _a; const reviewOrderRoute = this.checkoutStepService.getCheckoutStepRoute(CheckoutStepType.REVIEW_ORDER); return expressCheckoutPossible && reviewOrderRoute ? of(this.router.parseUrl((_a = this.routingConfigService.getRouteConfig(reviewOrderRoute) .paths) === null || _a === void 0 ? void 0 : _a[0])) : this.firstStep$; })); } return this.firstStep$; } } CheckoutGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutGuard, deps: [{ token: i3.Router }, { token: i1.RoutingConfigService }, { token: CheckoutConfigService }, { token: ExpressCheckoutService }, { token: i1.ActiveCartService }, { token: CheckoutStepService }], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutGuard, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutGuard, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: i3.Router }, { type: i1.RoutingConfigService }, { type: CheckoutConfigService }, { type: ExpressCheckoutService }, { type: i1.ActiveCartService }, { type: CheckoutStepService }]; } }); class CheckoutOrchestratorComponent { constructor() { } } CheckoutOrchestratorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrchestratorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); CheckoutOrchestratorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: CheckoutOrchestratorComponent, selector: "cx-checkout-orchestrator", ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrchestratorComponent, decorators: [{ type: Component, args: [{ selector: 'cx-checkout-orchestrator', template: '', changeDetection: ChangeDetectionStrategy.OnPush, }] }], ctorParameters: function () { return []; } }); class CheckoutOrchestratorModule { } CheckoutOrchestratorModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrchestratorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); CheckoutOrchestratorModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrchestratorModule, declarations: [CheckoutOrchestratorComponent], imports: [CommonModule], exports: [CheckoutOrchestratorComponent] }); CheckoutOrchestratorModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrchestratorModule, providers: [ provideDefaultConfig({ cmsComponents: { CheckoutOrchestrator: { component: CheckoutOrchestratorComponent, guards: [CheckoutAuthGuard, CartNotEmptyGuard, CheckoutGuard], }, }, }), ], imports: [[CommonModule]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrchestratorModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule], providers: [ provideDefaultConfig({ cmsComponents: { CheckoutOrchestrator: { component: CheckoutOrchestratorComponent, guards: [CheckoutAuthGuard, CartNotEmptyGuard, CheckoutGuard], }, }, }), ], declarations: [CheckoutOrchestratorComponent], exports: [CheckoutOrchestratorComponent], }] }] }); class CheckoutOrderSummaryComponent { constructor(activeCartService) { this.activeCartService = activeCartService; this.cart$ = this.activeCartService.getActive(); } } CheckoutOrderSummaryComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrderSummaryComponent, deps: [{ token: i1.ActiveCartService }], target: i0.ɵɵFactoryTarget.Component }); CheckoutOrderSummaryComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: CheckoutOrderSummaryComponent, selector: "cx-checkout-order-summary", ngImport: i0, template: "<cx-order-summary [cart]=\"cart$ | async\"></cx-order-summary>\n", components: [{ type: i4.OrderSummaryComponent, selector: "cx-order-summary", inputs: ["cart"] }], pipes: { "async": i3$2.AsyncPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrderSummaryComponent, decorators: [{ type: Component, args: [{ selector: 'cx-checkout-order-summary', templateUrl: './checkout-order-summary.component.html', changeDetection: ChangeDetectionStrategy.OnPush, }] }], ctorParameters: function () { return [{ type: i1.ActiveCartService }]; } }); class CheckoutOrderSummaryModule { } CheckoutOrderSummaryModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrderSummaryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); CheckoutOrderSummaryModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrderSummaryModule, declarations: [CheckoutOrderSummaryComponent], imports: [CommonModule, CartSharedModule], exports: [CheckoutOrderSummaryComponent] }); CheckoutOrderSummaryModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrderSummaryModule, providers: [ provideDefaultConfig({ cmsComponents: { CheckoutOrderSummary: { component: CheckoutOrderSummaryComponent, }, }, }), ], imports: [[CommonModule, CartSharedModule]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutOrderSummaryModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, CartSharedModule], providers: [ provideDefaultConfig({ cmsComponents: { CheckoutOrderSummary: { component: CheckoutOrderSummaryComponent, }, }, }), ], declarations: [CheckoutOrderSummaryComponent], exports: [CheckoutOrderSummaryComponent], }] }] }); class CheckoutStepsSetGuard { constructor(paymentTypeService, checkoutStepService, checkoutDetailsService, routingConfigService, checkoutCostCenterService, router) { this.paymentTypeService = paymentTypeService; this.checkoutStepService = checkoutStepService; this.checkoutDetailsService = checkoutDetailsService; this.routingConfigService = routingConfigService; this.checkoutCostCenterService = checkoutCostCenterService; this.router = router; } canActivate(route, _) { let currentIndex = -1; const currentRouteUrl = '/' + route.url.join('/'); // check whether the previous step is set return combineLatest([ this.checkoutStepService.steps$, this.paymentTypeService.isAccountPayment(), ]).pipe(tap(([, isAccount]) => { this.checkoutStepService.disableEnableStep(CheckoutStepType.PAYMENT_DETAILS, isAccount); }), take(1), switchMap(([steps, isAccount]) => { currentIndex = steps.findIndex((step) => { var _a; const stepRouteUrl = `/${(_a = this.routingConfigService.getRouteConfig(step.routeName).paths) === null || _a === void 0 ? void 0 : _a[0]}`; return stepRouteUrl === currentRouteUrl; }); // get current step let currentStep; if (currentIndex >= 0) { currentStep = steps[currentIndex]; } if (Boolean(currentStep)) { return this.isStepSet(steps[currentIndex - 1], isAccount); } else { if (isDevMode()) { console.warn(`Missing step with route '${currentRouteUrl}' in checkout configuration or this step is disabled.`); } return of(this.getUrl('checkout')); } })); } isStepSet(step, isAccountPayment) { if (step && !step.disabled) { switch (step.type[0]) { case CheckoutStepType.PAYMENT_TYPE: { return this.isPaymentTypeSet(step); } case CheckoutStepType.SHIPPING_ADDRESS: { return this.isShippingAddressAndCostCenterSet(step, isAccountPayment); } case CheckoutStepType.DELIVERY_MODE: { return this.isDeliveryModeSet(step); } case CheckoutStepType.PAYMENT_DETAILS: { return this.isPaymentDetailsSet(step); } case CheckoutStepType.REVIEW_ORDER: { break; } } } return of(true); } isPaymentTypeSet(step) { return this.paymentTypeService.getSelectedPaymentType().pipe(map((paymentType) => { if (Boolean(paymentType)) { return true; } else { return this.getUrl(step.routeName); } })); } isShippingAddressAndCostCenterSet(step, isAccountPayment) { return combineLatest([ this.checkoutDetailsService.getDeliveryAddress(), this.checkoutCostCenterService.getCostCenter(), ]).pipe(map(([deliveryAddress, costCenter]) => { if (isAccountPayment) { if (deliveryAddress && Object.keys(deliveryAddress).length && Boolean(costCenter)) { return true; } else { return this.getUrl(step.routeName); } } else { if (deliveryAddress && Object.keys(deliveryAddress).length && costCenter === undefined) { return true; } else { return this.getUrl(step.routeName); } } })); } isDeliveryModeSet(step) { return this.checkoutDetailsService .getSelectedDeliveryModeCode() .pipe(map((mode) => mode && mode.length ? true : this.getUrl(step.routeName))); } isPaymentDetailsSet(step) { return this.checkoutDetailsService .getPaymentDetails() .pipe(map((paymentDetails) => paymentDetails && Object.keys(paymentDetails).length !== 0 ? true : this.getUrl(step.routeName))); } getUrl(routeName) { var _a; return this.router.parseUrl((_a = this.routingConfigService.getRouteConfig(routeName).paths) === null || _a === void 0 ? void 0 : _a[0]); } } CheckoutStepsSetGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutStepsSetGuard, deps: [{ token: i1$1.PaymentTypeFacade }, { token: CheckoutStepService }, { token: CheckoutDetailsService }, { token: i1.RoutingConfigService }, { token: i1$1.CheckoutCostCenterFacade }, { token: i3.Router }], target: i0.ɵɵFactoryTarget.Injectable }); CheckoutStepsSetGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutStepsSetGuard, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: CheckoutStepsSetGuard, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () {