import { Injectable } from '@angular/core'; import { CookiesService } from '../../services/cookies/cookies.service'; import { apiParams, apiParamsCartScheme } from '../../constants/api.constants'; import { pageCookies, userCookies, cartCookies } from '../../constants/cookie.constants'; import { LanguageService } from '../../services/router-language/route-language.service'; @Injectable() export class ApiParamInfoService { constructor( private cookieService: CookiesService, private languageService: LanguageService) {} /** * Get API Param information: * - lang: page language base on `Lang` cookie * - customerId: which is page user id such as `anonymou` or generated uuid * - cartId: cart id generated while created cart * - localizedPOS: which default user postal code * - fields: which is `FULL_SPA` for cart 2.0 * - catalogVersion: which is `Online` * return {object} - contains: * - lang * - customerId * - cartId * - localizedPOS * - fields * - catalogVersion * **/ getApiParamInfo(cartSchema?: boolean) { const lang = this.languageService.getLanguage(); const customerId = typeof window !== 'undefined' ? this.cookieService.getCookie(userCookies.EMAIL) ? this.cookieService.getCookie(userCookies.EMAIL) : apiParams.DEFAULT_USER : ''; const cartId = typeof window !== 'undefined' ? this.cookieService.getCookie(cartCookies.CART) : ''; const localizedPOS = typeof window !== 'undefined' ? this.cookieService.getCookie(cartCookies.STORE) ? this.cookieService.getCookie(cartCookies.STORE) : apiParams.DEFAULT_POS : ''; const trackingId = typeof window !== 'undefined' ? this.cookieService.getCookie(pageCookies.RES_TRACKINGID) ? this.cookieService.getCookie(pageCookies.RES_TRACKINGID) : apiParams.TRACKING_ID : ''; const fields_full = apiParams.FIELDS_FULL; const fields_full_spa = apiParams.FIELDS_FULL_SPA; const catalogVersion = apiParams.CATALOG_VERSION; const scheme = cartSchema ? apiParamsCartScheme.SCHEME : apiParams.SCHEME; const relationship = cartSchema ? apiParamsCartScheme.RELATIONSHIP : apiParams.RELATIONSHIP; return { lang: lang, customerId: customerId, cartId: cartId, localizedPOS: localizedPOS, full: fields_full, full_spa : fields_full_spa, catalogVersion: catalogVersion, scheme: scheme, relationship: relationship, trackingId: trackingId }; } }