/** * @Component Name: ConfirmComponent * @Module: Checkout * @Module Functionality : To display the confirm section * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnInit, OnDestroy } from '@angular/core'; import { Router } from '@angular/router'; // import { ORDER_STATUS } from '../../shared/form.constants'; // import * as Constants from '../../shared/constants'; import CartUtils from '../../shared/cart.utils'; // import { Cart } from '../../shared/modal/cart'; import { Customer } from '../../shared/modal/customer'; // import { IShipping, IRealtimeInventory } from '../../shared/modal/common'; import { SharedService } from '../../shared/shared.service'; import { CustomerService } from '../../services/customer.service'; import { CartService } from '../../services/cart.service'; @Component({ selector: 'confirm-cmp', moduleId: module.id, templateUrl: 'confirm.component.html', styleUrls: ['confirm.component.css'] }) export class ConfirmComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'ConfirmComponent'; storeId: number; // update storeid cart: any; customer: Customer; isBYOSOnlyOrder: boolean = false; enrollAutopay: boolean = false; constructor( public router: Router, public sharedService: SharedService, public customerService: CustomerService, public cartService: CartService) { } /** * This function is used to initialize the directive/component after Angular * first displays the data-bound properties.It is invoked only once when the * directive is instantiated.This function is initializing autopay indicator and * cart getCartSummary for this component * @return {void} */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; // this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Loading order confirmation page'); this.sharedService.updateErrorMessage(null); this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); this.cart = this.cartService.getCart(); if (!this.cart) { this.router.navigate(['home/search']); } this.enrollAutopay = (this.cart.totalAutopayDiscountDueMonthly > 0) ? true : false; this.isBYOSOnlyOrder = CartUtils.isBYOSOnlyOrder(this.cart); if (this.cart && this.cart.packages) { console.log('Updating the current cart information.'); // clearing order details from local storage this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.cart = Object.assign(this.cart, result); for (const item of this.cart.packages) { item.showPackage = false; } this.cart.packages[0].showPackage = true; }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>'+ error); }); // getting the customer profile this.getCustomerProfile(this.cart.orderId); } } /** * Cleanup just before Angular destroys the directive/component. * Unsubscribe Observables and detach event handlers to avoid memory leaks. * @return {void} */ ngOnDestroy(): void { const METHOD_NAME: string = 'ngOnDestroy()'; // clearing all session data except user info this.cart = null; this.customer = null; this.sharedService.setAppDefault(); this.sharedService.clearSessionStorage(false); } /** * This function is used to get the customer profile * from getCustomerProfile of customer service. * @param {number} orderId - order id to refer the order details * @return {void} */ getCustomerProfile(orderId: number): void { const METHOD_NAME: string = 'getCustomerProfile()'; console.log('ConfirmComponent.showOrderCustomer()>>Start.'); this.sharedService.showSpinner(true); // spinner this.customerService.getCustomerProfile(this.storeId, orderId, null).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.customer = result; }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error); }); } }