-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
287 lines (229 loc) · 11 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/* source: <cosmo.checkout-ui-settings> */
// WARNING: THE USAGE OF CUSTOM SCRIPTS IS NOT SUPPORTED. VTEX IS NOT LIABLE FOR ANY DAMAGES THIS MAY CAUSE. THIS MAY BREAK YOUR STORE AND STOP SALES. IN CASE OF ERRORS, PLEASE DELETE THE CONTENT OF THIS SCRIPT.
window.onload = () => {
const addElements = () => {
const items = window?.API?.orderForm?.items
if (document) {
// Add header title
const heading = document.createElement('h1')
heading.classList.add('heading');
heading.textContent = 'Your Cart'
const headingHtml = document.getElementsByClassName('checkout-container')[0]
headingHtml.prepend(heading)
// Add unit price heading
const unitTh = document.createElement('th')
unitTh.innerHTML = 'Unit Price'
unitTh.classList.add('unit-price')
const quantityTh = document.querySelector('th.quantity')
quantityTh?.parentNode.insertBefore(unitTh, quantityTh)
// CHECKOUT BUTTON AREA
// Create Order Summary title
const orderSummary = document.createElement('h2')
orderSummary.classList.add('order-summary')
orderSummary.textContent = 'Order Summary'
document.querySelector('.accordion-inner').prepend(orderSummary)
// Move coupon field
const discountRow = document.createElement('tr')
const couponFieldTd = document.createElement('td')
const discountTd = document.createElement('td')
discountTd.innerText = 'Discount'
discountTd.classList.add('discount')
const couponForm = document.querySelector('.coupon.summary-coupon.pull-right')
couponFieldTd.appendChild(couponForm)
discountRow.classList.add('discount-row')
discountRow.appendChild(discountTd)
discountRow.appendChild(couponFieldTd)
// Create tax row
const taxRow = document.createElement('tr')
const taxTextTd = document.createElement('td')
const taxNumberTd = document.createElement('td')
taxTextTd.innerText = 'Tax'
taxTextTd.classList.add('tax')
taxNumberTd.innerText = '-'
taxNumberTd.classList.add('tax-number')
taxRow.appendChild(taxTextTd)
taxRow.appendChild(taxNumberTd)
document.querySelector('.totalizers-list').appendChild(discountRow)
document.querySelector('.totalizers-list').appendChild(taxRow)
// Make accordion
const accordionBox = document.createElement('div')
accordionBox.classList.add('accordion-box')
const accordionButtonBox = document.createElement('div')
accordionButtonBox.classList.add('accordion-button-box')
const accordionButton = document.createElement('button')
accordionButton.classList.add('accordion')
const accordionText = document.createElement('p')
accordionText.textContent = 'Show order summary'
const toggleDiv = document.createElement('div')
const toggleImage = document.createElement('span')
toggleImage.classList.add('arrow')
toggleImage.classList.add('up')
toggleDiv.appendChild(toggleImage)
accordionButton.appendChild(accordionText)
accordionButton.appendChild(toggleDiv)
const totalAmount = document.querySelector('.new-product-price').innerText
const totalAmountText = document.createElement('div')
totalAmountText.textContent = totalAmount
totalAmountText.classList.add('total-amount-text')
accordionButtonBox.appendChild(accordionButton)
accordionButtonBox.appendChild(totalAmountText)
const accordionPanel = document.querySelector('.accordion-inner')
accordionPanel.classList.add('panel')
accordionBox.appendChild(accordionButtonBox)
accordionBox.appendChild(accordionPanel)
document.querySelector('.summary-template-holder').prepend(accordionBox)
accordionButton.addEventListener('click', function() {
accordionButton.classList.toggle('active')
toggleImage.classList.toggle('down')
if (accordionButton.classList.contains('active')) {
accordionPanel.style.display = 'block'
totalAmountText.style.display = 'none'
accordionText.textContent = 'Hide order summary'
} else {
accordionPanel.style.display = 'none'
totalAmountText.style.display = 'block'
accordionText.textContent = 'Show order summary'
}
});
// Create modal
const quoteButton = document.createElement('button')
quoteButton.textContent = 'Need a quote?'
quoteButton.classList.add('quote-button')
const modal = document.createElement('div')
modal.classList.add('quote-modal')
const modalContent = document.createElement('div')
modalContent.classList.add('modal-content')
modal.appendChild(modalContent)
const closeIcon = document.createElement('span')
closeIcon.classList.add('close-icon')
const modalText = document.createElement('p')
modalText.classList.add('modal-text')
modalText.innerHTML = 'To request a quote, simply add the desired items to your cart and continue to checkout. Once at the final payment screen, you will have the option to <b>“REQUEST AN OFFICIAL QUOTE"</b> (if required) or select a payment method and <b>“PLACE ORDER”</b>.'
modalContent.appendChild(closeIcon)
modalContent.appendChild(modalText)
document.querySelector('.cart-links-bottom').appendChild(quoteButton)
document.querySelector('body').prepend(modal)
// Modal functionality
quoteButton.onclick = function() {
modal.style.display = 'flex'
}
closeIcon.onclick = function() {
modal.style.display = 'none'
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = 'none'
}
}
}
}
// Timeout ensures that data is loaded before DOM manipulation
setTimeout(addElements, 500);
};
/* source: <vtex.email-checkout-conflict> */
window.checkEmailAuthConflictMessages = {
en: {
title:"Emails conflict",
button:"Login",
message:"We have identified that you probably used a different login email than the one you entered previously. Please log in again by clicking the button below."
},
es: {
title:"Conflicto de correos electrónicos",
button:"Ingressar",
message:"Hemos identificado que probablemente utilizó una dirección de correo electrónico de inicio de sesión diferente a la que ingresó anteriormente. Vuelva a iniciar sesión haciendo clic en el botón de abajo."
},
ro: {
title:"Conflict adresa email",
button:"Loghează-te",
message:"Am identificat că probabil ați folosit un alt e-mail de conectare decât cel introdus anterior. Vă rugăm să vă conectați din nou făcând clic pe butonul de mai jos."
}
}
class checkEmailAuthConflict {
constructor({} = {}) {
this.orderForm = "";
this.lang = "";
}
removeModal() {
$(".checkEmailAuthConflict__modal").fadeOut("normal", function() {
$(".checkEmailAuthConflict__modal").remove();
});
}
showModal() {
const _this = this;
$(".checkEmailAuthConflict__modal").remove();
if(!_this.lang) return false;
if(!checkEmailAuthConflictMessages[this.lang]) this.lang = "en";
let modal = `
<div class="checkEmailAuthConflict__modal">
<div class="checkEmailAuthConflict__modal--bg"></div>
<div class="checkEmailAuthConflict__modal--wrap">
<h4 class="checkEmailAuthConflict__modal--title">${checkEmailAuthConflictMessages[this.lang].title}</h4>
<p class="checkEmailAuthConflict__modal--text">${checkEmailAuthConflictMessages[this.lang].message}</p>
<button class="checkEmailAuthConflict__modal--button js-checkEmailAuthConflict__modal--button">${checkEmailAuthConflictMessages[this.lang].button}</button>
</div>
</div>
`;
$("body").append(modal);
}
bind() {
const _this = this;
$("body").on("click", ".js-checkEmailAuthConflict__modal--button", function(e) {
e.preventDefault();
$(this).addClass("js-loading");
_this.changeUser();
})
}
changeUser() {
const _this = this;
$.ajax(`/checkout/changeToAnonymousUser/${_this.orderForm.orderFormId}`)
.done(function() {
_this.removeModal();
vtexid.start();
});
}
validate() {
const _this = this;
try {
if(
_this.orderForm &&
_this.orderForm.clientProfileData &&
_this.orderForm.clientProfileData.email
) {
fetch('/api/vtexid/pub/authenticated/user', {credentials: 'include'})
.then(response => response.json())
.then(function(response) {
if(!response) return false;
let user = response.user;
if(_this.orderForm.clientProfileData.email != user) {
_this.showModal();
}
})
}
} catch(e) {
console.error(e)
}
}
init() {
const _this = this;
$(window).one('orderFormUpdated.vtex', function(_, orderForm) {
if (orderForm.userType === 'callCenterOperator') return
_this.orderForm = orderForm;
_this.lang = vtex ? vtex.i18n.locale : "en";
try {
_this.validate();
_this.bind();
} catch(e) {
console.error(e)
}
});
$(window).on('authenticatedUser.vtexid closed.vtexid', function() {
_this.orderForm = vtexjs.checkout.orderForm;
if (_this.orderForm.userType === 'callCenterOperator') return
try {
_this.validate();
} catch(e) {
console.error(e)
}
});
}
}