1"use strict"; 2angular 3 .module("sfmStore") 4 .controller("checkoutController", function( 5 $scope, 6 $stateParams, 7 $state, 8 $checkout, 9 $order, 10 $analytics 11 ) { 12 var vm = this; 13 var order = $order.order; 14 $order.getTotal(); 15 vm.analytics = $analytics; 16 vm.debug = true; 17 vm.error = false; 18 vm.errorDetails = null; 19 vm.profile = $order.getProfile(); 20 vm.payment = order.payment || { payment_method: "check" }; 21 vm.items = order.details.items; 22 vm.coupon = order.details.coupon; 23 vm.couponFailed = false; 24 vm.originalTotal = order.details.originalTotal; 25 vm.subTotal = order.details.total; 26 vm.plus = Number(order.school.plus) || 0; 27 vm.orderPlaced = false; 28 vm.showShipping = order.details.items.filter(function(item) { 29 return Number(item.physical_item) === 1; 30 }); 31 vm.noSchool = $order.getSchool().School_Name ? false : true; 32 // disable paypal button if user hasn't agrred to terms and services 33 vm.payment.payPalEnabledByAgreement = false 34 // 1/20/22 want to disable paypal for insurance orders b/c: 35 // 1) not sure if broker offers pay later and paypal credit options; in theory they should, but this needs to be confirmed 36 // 2) The vigorish that paypal takes starts to get pretty high north of $300 purchases 37 var findInsurance = vm.items.find(function(item) { return item.category_id === "1040"}) 38 vm.payment.disablePayPal = (findInsurance !== undefined) ? true : false 39 40 vm.hasExpo = vm.items.find(function(item) { return item.category_id === "1009" }) 41 vm.profile.expo_opt_in = 1; 42 43 $scope.$watch( 44 function() { 45 return order.school.plus; 46 }, 47 function(newVal) { 48 vm.plus = Number(newVal); 49 $order.getTotal(); 50 vm.subTotal = order.details.total; 51 } 52 ); 53 54 vm.processCoupon = function() { 55 $checkout.processCoupon(this.couponCode).then(function(res) { 56 if (res.data.data) { 57 vm.originalTotal = angular.copy(order.details.total); 58 $order.addCoupon(res.data.data); 59 vm.coupon = res.data.data; 60 $order.getTotal(); 61 if (vm.originalTotal == $order.getTotal()) { 62 vm.couponFailed = true; 63 } 64 vm.subTotal = order.details.total; 65 } else { 66 vm.couponFailed = true; 67 } 68 }); 69 }; 70 71 vm.removeCoupon = function() { 72 vm.coupon = {}; 73 vm.couponCode = null; 74 vm.couponFailed = false; 75 $order.removeCoupon(); 76 $order.getTotal(); 77 vm.originalTotal = 0; 78 vm.subTotal = order.details.total; 79 }; 80 81 vm.checkout = function(checkoutForm) { 82 if (checkoutForm.$valid) { 83 if ($order.getSchool().School_Name) { 84 vm.noSchool = false; 85 vm.profile.send_to = vm.profile.send_to || "school"; 86 vm.profile.school_id = 87 $order.getSchool().School_ID || $order.getSchool().id; 88 89 $order.updatePayment(vm.payment, vm.profile.billing); 90 vm.orderPlaced = true; 91 92 // if we have a check payment, we have to reconcile the eff and exp dates of incoming policy for renewal products 93 // if policy HAS EXPIRED, eff and exp date will offset from the day that the payment has been received. Until then, 94 // offset dates should be from when the order was made 95 // if policy HAS YET TO EXPIRE, need to set eff and exp to ( current_exp / current_exp + 1 year ) 96 if (vm.payment.pay_by_check) { 97 var d = new Date().toISOString(); 98 var plusOneYear = new Date(new Date().setFullYear(new Date().getFullYear() + 1)).toISOString() 99 order.details.items.map(function(item) { 100 if (item.questions) { 101 var itemCondition = (item.type === "rnwl"); 102 var dateCondition = (d > item.questions.oldExpDate); 103 if (itemCondition && dateCondition) { 104 item.questions.effectiveDate = d; 105 item.questions.expirationDate = plusOneYear; 106 } 107 } 108 return item 109 }) 110 } 111 // filling this value here, at the checkout screen, instead of expo order screen 112 order.profile.expo_opt_in = vm.hasExpo ? vm.profile.expo_opt_in : null; 113 114 $order.processOrder().then( 115 function(res) { 116 if (res.data.success) { 117 var items = [];
118 vm.items.forEach(function(item) { 119 items.push({ 120 'item_name': item.name, // Name or ID is required. 121 'item_id': item.id, 122 'price': item.cost, 123 'item_category': item.category_id, 124 'quantity': item.qty 125 }) 126 }) 127 128 dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object. 129 dataLayer.push({ 130 'event': 'begin_checkout', 131 'ecommerce': { 132 'items': items 133 } 134 }); 135 136 $state.go("confirmation", { data: res.data.data }); 137 return; 138 } else { 139 vm.error = true; 140 vm.errorDetails = res.data; 141 vm.orderPlaced = false; 142 return; 143 } 144 }, 145 function(res) { 146 vm.error = true; 147 vm.orderPlaced = false; 148 return; 149 } 150 ); 151 } else { 152 vm.noSchool = true; 153 } 154 } else { 155 angular.forEach(checkoutForm.$error.required, function(field) { 156 field.$setDirty(); 157 angular.forEach(field.$error.required, function(nestedField) { 158 nestedField.$setDirty(); 159 }); 160 }); 161 } 162 }; 163 $analytics.pushVirtualPageview(window.location.href); 164 });
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.