UNPKG

@nuskin/ns-checkout

Version:

Ecomm3 Checkout module

199 lines (172 loc) • 8.33 kB
import {BuyerCookieService, UserService} from '@nuskin/ns-account'; import {ShopContextService, LocalStorageOrderService, AdrService, Cart, newShop, CartService, PaymentType} from '@nuskin/ns-shop'; import {ConfigService, RunConfigService, StringService} from '@nuskin/ns-util'; import {StringUtil} from '@nuskin/ns-checkout-common'; import '../app.js'; 'use strict'; angular.module('checkout').controller('AdrUpdateConfirmationCtrl', ['$scope','$location','$http','nsUtil', 'tdcService','nusAnalyticsService', function($scope, $location, $http, nsUtil, tdcService, nusAnalytics) { var SHIPIMMEDIATE = "shipImmediate"; var ORDER = "order"; var ADR = "adrFuture"; $scope.tdc = tdcService.getTdc('checkout'); $scope.contentLoaded = false; $scope.runConfig = RunConfigService.getRunConfig(); $scope.buyer = BuyerCookieService.getBuyer(); $scope.user = UserService.getUser(); $scope.PaymentType = PaymentType; $scope.showPsv = ShopContextService.showPsv($scope.buyer ? $scope.buyer.accountType : 0); $scope.orderList = LocalStorageOrderService.getOrders(); if ($scope.orderList === undefined) { // always going to landing page (cart) if the order is empty... window.location = $scope.runConfig.landing; return; } $scope.order = $scope.orderList.getLastCompletedOrder(); if ($scope.order === undefined) { // always going to landing page (cart) if the order is empty... window.location = $scope.runConfig.landing; //alert($scope.runConfig.landing); return; } $scope.signup = CartService.getCartProperty('inSignup'); $scope.scanCards = CartService.getScanCards(); $scope.adr = AdrService.getAdrDraft(); $scope.config = ConfigService.getMarketConfig(); $scope.showWebSavings = !$scope.order.adr && $scope.config.checkout.showWebSavings; $scope.webSavings = 0.0; $scope.order.currencyCode = $scope.runConfig.currencyCode; $scope.logoADRUrl = $scope.config.siteUrl + "/content/dam/global/images/logo-adr.svg"; $scope.logoAROUrl = $scope.config.siteUrl + "/content/dam/global/images/logo-aro-gray.svg"; $scope.logoADPUrl = $scope.config.siteUrl + "/content/dam/global/images/logo-adp-gray.svg"; StringUtil.initStrings($scope, $scope.runConfig); //********************************************************************************* // Private Functions //********************************************************************************* function sendDTMData() { nusAnalytics.setPageDefaults($scope.runConfig.language, $scope.runConfig.country, "ADR Update Confirmation"); if (newShop) { newShop.orderDetail = newShop.orderDetail || {}; CartService.setCartString($scope.order.adr, ($scope.adr ? $scope.adr.shipImmediate : null)); newShop.orderDetail.currencyCode = $scope.order.currencyCode; newShop.orderDetail.flow = $scope.order.singleFlow ? "single" : "dual"; newShop.orderDetail.orderNumber = !($scope.order.adr && ($scope.order.adrOverrideNumber == null)) ? $scope.order.orderId : ""; if ($scope.order.adr) { newShop.orderDetail.adrNumber = $scope.order.adrOverrideNumber === null ? $scope.order.orderId : $scope.order.adrOverrideNumber; } if ($scope.order.adr && $scope.adr.shipImmediate) { newShop.orderDetail.orderType = SHIPIMMEDIATE; } else if ($scope.order.adr) { newShop.orderDetail.orderType = ADR; } else { newShop.orderDetail.orderType = ORDER; } nusAnalytics.setAction("Order_Details", newShop.orderDetail); } if (typeof _satellite !== 'undefined') { //TODO After Japan beta is over remove this check if (window.location.href.indexOf("JP") >= 0) { _satellite.track("japan.complete"); nusAnalytics.setState("japan.complete", { japan: "complete"}); } else { _satellite.track("order.complete"); nusAnalytics.setState("order.complete", { order : "complete"}); } } } function loadCommonStrings() { // Get the PSV label from the common strings var accountType = !$scope.isGuestCheckout ? $scope.buyer.accountType : "20"; StringService.getPsvString(accountType).then(psvLabel => { $scope.psvLabel = psvLabel; $scope.$apply(); }); } function setWebSavings() { var orderTotals = $scope.order.orderTotals, tax = orderTotals['taxInclusive'] ? orderTotals['tax'] : 0.0, price = orderTotals['grandTotal'], // price with tax and shipping shipping = orderTotals['shipping'], nonWebPrice, // total of items without savings ... does not include tax or shipping buyer = $scope.buyer, priceType = buyer.priceType == 'PRF' ? 'WHL' : buyer.priceType, savings; nonWebPrice = CartService.getPriceTypeTotal(priceType); savings = nonWebPrice - (price - tax - shipping); $scope.webSavings = savings > 0.0 ? savings : 0.0; } function checkForSignup() { if ($scope.signup) { $scope.confirmationSpinner = true; $http({ method: 'GET', url: ConfigService.getMarketConfig().nsurl_accountService + "/extended/" + $scope.buyer.id + "?eid=" + $scope.user.eid, headers: { 'client_id': ConfigService.getMarketConfig().checkout.clientId, 'client_secret': ConfigService.getMarketConfig().checkout.clientSecret }, params: { cntryCd: $scope.runConfig.country } }).then(function(data) { $scope.signupDetail = data; angular.forEach($scope.signupDetail.BeReadResponse.Contact, function(c) { if (c.Value.Type === 'EMAIL') { $scope.signupDetail.username= c.Value.value; } }); $scope.confirmationSpinner = false; }, function() { $scope.confirmationSpinner = false; }); } } sendDTMData(); if ($scope.showWebSavings) { setWebSavings(); } checkForSignup(); loadCommonStrings(); CheckoutApi.cleanupOrder(); $scope.contentLoaded = true; $scope.stateValueName = ''; //************************************************************************* // Scope functions //************************************************************************* /** getLineItemClass is just retr */ $scope.getLineItemClass = function(cartItem) { if (cartItem.isAdr() && !cartItem.isBusinessPortfolio()) { return 'adrRow'; } return 'noAdrRow'; }; $scope.goHome = function() { window.location = 'index.html#/home'; // we are always in the assessment app here. /* if ($scope.runConfig.alternateHomeUrl && $scope.runConfig.alternateHomeUrl.length > 0) { window.location = $scope.runConfig.alternateHomeUrl; if ($scope.runConfig.addSkusToLandingPage === true) { window.location = CartService.getOrderSkuQueryParams(true); } } else { window.location = 'home.html'; } */ }; $scope.goToCart = function() { if ($scope.runConfig.cartUrl && $scope.runConfig.cartUrl.length > 0) { window.location = $scope.runConfig.cartUrl; } else { window.location = 'cart.html'; } }; $scope.printConfirmation = function() { window.print(); }; $scope.getFormattedCCExpiration = function(){ var formattedCCExpiration = ""; if ($scope.order && $scope.order.selectedPayment && $scope.order.selectedPayment.expMonth && $scope.order.selectedPayment.expYear){ formattedCCExpiration = $scope.order.selectedPayment.expMonth + '/' + $scope.order.selectedPayment.expYear; } return formattedCCExpiration; }; }]);