/** * @Component Name: HardGoodsComponent * @Module: Home * @Module Functionality : To display the full cart section * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnInit, OnDestroy, OnChanges } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { NgClass } from '@angular/common'; 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, IDormantProperties } from '../../../shared/modal/common'; import { SharedService } from '../../../shared/shared.service'; import { UserService } from '../../../services/user.service'; import { CartService } from '../../../services/cart.service'; @Component({ selector: 'hard-goods-cmp', moduleId: module.id, templateUrl: 'hard-goods.component.html', styleUrls: ['hard-goods.component.css'] }) export class HardGoodsComponent implements OnInit, OnChanges, OnDestroy { private COMPONENT_NAME: string = 'HardGoodsComponent'; storeId: number = 10553; orderStatusItems: any[]; todayDate = new Date(); refTypeExchange: string = Constants.REF_TYPE_EXCHANGE; @Input() cart: Cart; @Input() customer: Customer; shippingInfo: IShipping; realTimeInventory: IRealtimeInventory; isFinanceOrder: boolean = false; isVirtualOnlyOrder: boolean = false; dormanProperties: IDormantProperties; // canOverrideRemorse constructor( public router: Router, public sharedService: SharedService, public userService: UserService, 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.Here it is initializing all the states, payment methods and card types * @returns void */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; this.orderStatusItems = ORDER_STATUS.filter(orderStatusItem => orderStatusItem); this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); this.dormanProperties = this.sharedService.getDormantProperties(); } /** * This function is called whenever one or more data-bound input properties change * @returns void */ ngOnChanges(): void { this.isFinanceOrder = CartUtils.isFinanceOrder(this.cart); // added to check if order is virtual only this.isVirtualOnlyOrder = CartUtils.isVirtualOnlyOrder(this.cart); if (this.cart) { this.realTimeInventory = this.cart.realTimeInventory ? this.cart.realTimeInventory : null; // getting the shipping address this.getShippingAddress(this.cart.orderId); } } /** * Cleanup just before Angular destroys the directive/component. * Unsubscribe Observables and detach event handlers to avoid memory leaks. * @returns void */ ngOnDestroy(): void { this.cart = null; this.customer = null; this.shippingInfo = null; this.realTimeInventory = null; this.orderStatusItems = null; } /** * This function is used to get the shipping address from getCartShipping from cartService * @param {number} orderId * @returns void */ getShippingAddress(orderId: number): void { const METHOD_NAME: string = 'getShippingAddress()'; console.log('OrderDetailComponent.showOrderShipping()>>Start.'); this.sharedService.showSpinner(true); // spinner this.cartService.getCartShipping(this.storeId, orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.shippingInfo = result; }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error); }); } /** * This function is used to get the value of status label from key value pair * @param {string} status * @returns string */ getStatusLabel(status: string): string { const METHOD_NAME: string = 'getStatusLabel()'; for (const item of this.orderStatusItems) { if (item.key === status) { return item.value; } } return Constants.NOT_FOUND; } /** * This function is used to check whether to and from shipping dates are valid or not. * @returns boolean */ get hasShipDate(): boolean { const METHOD_NAME: string = 'hasShipDate()'; if (this.realTimeInventory) { if (this.realTimeInventory.quoteESDFromDate && this.realTimeInventory.quoteESDToDate) { return true; } } return false; } /** * This function is used to check whether to and from shipping dates are equal or not. * @returns boolean */ get isSameFromToDate(): boolean { const METHOD_NAME: string = 'isSameFromToDate()'; const shipFromDate: Date = new Date(this.realTimeInventory.quoteESDFromDate); const shipToDate: Date = new Date(this.realTimeInventory.quoteESDToDate); if (shipFromDate === shipToDate) { return true; } return false; } /** * This function is used to get the Email from cart or customer. * @returns string */ getCustomerEmail(): string { const METHOD_NAME: string = 'getCustomerEmail()'; if (this.cart && this.cart.esigEmail) { return this.cart.esigEmail; } else if (this.customer && this.customer.email1) { return this.customer.email1; } return ''; } }