/** * @Component Name: OffersComponent * @Module: Home * @Module Functionality : To display the product offers information * @Creation Date: August 16,2018 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnInit, OnDestroy } from '@angular/core'; import Utils from '../../shared/utils'; import { SharedService } from '../../shared/shared.service'; import { UserService } from '../../services/user.service'; @Component({ moduleId: module.id, selector: 'offers-cmp', templateUrl: 'offers.component.html', styleUrls: ['offers.component.css'] }) export class OffersComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'OffersComponent'; @Input() item: any; constructor( public sharedService: SharedService, public userService: UserService) { } /** * 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, ID Types, user and cart informations * @return {void} */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; } /** * 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()'; } /** * This function is used to get key,valye pairs of inventory status. * @param {IItem} item * @returns boolean */ get hasOffer(): boolean { return Utils.hasOffer(this.item); } /** * This function is used to get key,valye pairs of inventory status. * @param {IItem} item * @returns boolean */ get hasPCMOffer(): boolean { return (this.item && ((this.item.instantDiscount && this.item.instantDiscount > 0) || (this.item.openBoxDiscount && this.item.openBoxDiscount > 0) || (this.item.mailInRebate && this.item.mailInRebate > 0))) ? true : false; } /** * This function is used to get key,valye pairs of inventory status. * @param {IItem} item * @returns boolean */ get hasCMCOffer(): boolean { return (this.item && (this.item.promotions && this.item.promotions.length > 0)) ? true : false; } }