UNPKG

@nuskin/ns-checkout

Version:

Ecomm3 Checkout module

108 lines (89 loc) 4.72 kB
'use strict'; import '../app.js'; import {AdrConstants, CartService, AdrService} from '@nuskin/ns-shop'; import {ConfigService} from '@nuskin/ns-util'; angular.module('checkout').controller('AdrShipWhenCtrl', ['$scope', '$location', 'tdcService', 'nsADRType', 'nsAdrUtil', function($scope, $location, tdcService, nsADRType, nsAdrUtil) { var adrOptions = nsAdrUtil.getAdrOptions(), agelocme = ConfigService.getMarketConfig().agelocme; $scope.tdc = tdcService.getTdc('checkout'); $scope.adrType = {}; function init() { // setup the shipNowFuture dialog if (adrOptions.get(AdrConstants.ADR_MODE) === AdrConstants.IMMEDIATE_FUTURE) { $scope.option1Label = $scope.tdc.shipImmediateLabel; $scope.option2Label = $scope.tdc.shipFutureLabel; $scope.adrType.holder = nsADRType.getADRType(); // The adrType needs to be the selected option, not a copy of it, for the radio button to be selected. $scope.adrTypeValues = { one: nsADRType.equals($scope.adrType.holder, AdrConstants.IMMEDIATE) ? $scope.adrType.holder : AdrConstants.IMMEDIATE, two: nsADRType.equals($scope.adrType.holder, AdrConstants.FUTURE) ? $scope.adrType.holder : AdrConstants.FUTURE }; } else if (adrOptions.get(AdrConstants.ADR_MODE) === AdrConstants.DEFAULT_ALWAYS) { $scope.option1Label = $scope.tdc.defaultShipLabel; $scope.option2Label = $scope.tdc.shipAlwaysLabel; $scope.adrType.holder = AdrConstants.DEFAULT; if (!adrOptions.get(AdrConstants.USE_DFLT_FOR_IMMEDIATE_FIRST)) { // DEFAULT is not a shipImmediate type unless this flag is set. AdrConstants.DEFAULT.isImmediate = true; } // The adrType needs to be the selected option, not a copy of it, for the radio button to be selected. $scope.adrTypeValues = { one: nsADRType.equals($scope.adrType.holder, AdrConstants.DEFAULT) ? $scope.adrType.holder : AdrConstants.DEFAULT, two: nsADRType.equals($scope.adrType.holder, AdrConstants.ALWAYS) ? $scope.adrType.holder : AdrConstants.ALWAYS }; // For force shipAlways when cart has custom assessment if (adrOptions.get(AdrConstants.SHIP_ALWAYS_WITH_ASSESSMENT) && CartService.hasItems({cartAdrItems: true, cartAgelocMeFilter: {type: 'only', includeSku: (adrOptions.get(AdrConstants.SHIP_ALWAYS_WITH_CALIBRATION) ? agelocme.calibrationSku : '')}})) { $scope.showInfoFieldSet = true; $scope.option1disabled = true; $scope.optionalClass = 'withInfoFieldset'; $scope.adrType.holder = AdrConstants.ALWAYS; } } if (CartService.hasItems({cartOrderItems: true})) { if (CartService.getItemData({cartAdrItems: true}).some(item => item.isBusinessPortfolio)) { $scope.processFirstMessage = $scope.tdc.adrFirstMessage; } else { $scope.processFirstMessage = $scope.tdc.orderFirstMessage; } } function apply(_callback) { var callback = _callback || function() {}; if ($scope.$$phase != '$apply' && $scope.$$phase != '$digest') { $scope.$apply(callback); } else { callback(); } } // detect window width to determine button size. $scope.nsButtonSize = 'short'; function setNsButtonHeight() { apply(() => { $scope.nsButtonSize = $(window).width() >= 1023 ? 'short' : ''; }); } $(() => { setNsButtonHeight(); $(window).resize(() => { setNsButtonHeight(); }); }); } $scope.setAdrType = function() { nsADRType.setADRType($scope.adrType.holder); }; $scope.continue = function() { var adr = AdrService.getAdrDraft(); if (adr.shipImmediate != $scope.adrType.holder.isImmediate) { adr.shipImmediate = $scope.adrType.holder.isImmediate; AdrService.setAdrDraft(adr); if (!$scope.adrType.holder.isImmediate && $scope.adrType.holder.value == 'future') { // Tell the cart page to check for signup mode again as the BP will get removed from the cart. CartService.setCartProperties({checkForSignup: true}); } } nsADRType.setADRType($scope.adrType.holder); // adrOptions.set(AdrConstants.ADR_TYPE, $scope.adrType.holder); $location.path('/orderSummary'); }; init(); }]);