notify-me-wl 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -296
- package/index.js +179 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,301 +60,5 @@ https://api.au-sandbox.thewishlist.io/services/wsservice/api/wishlist/items/cust
|
|
|
60
60
|
https://api.au-aws.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
### Full Script
|
|
65
|
-
|
|
66
|
-
```javascript
|
|
67
|
-
// Access token for the API
|
|
68
|
-
const ACCESS_TOKEN = "123"; // Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
|
|
69
|
-
const TENANT_ID = "victoria-woods"; // Replace `TENANT_ID` with your actual tenant ID.
|
|
70
|
-
|
|
71
|
-
document.addEventListener("DOMContentLoaded", function () {
|
|
72
|
-
const wrapper = document.getElementById("notification-widget");
|
|
73
|
-
if (!wrapper) return;
|
|
74
|
-
|
|
75
|
-
// Define and apply styles for the popup and button
|
|
76
|
-
const styles = `
|
|
77
|
-
.notification-btn {
|
|
78
|
-
background-color: #fff;
|
|
79
|
-
border: 1px solid black;
|
|
80
|
-
color: black;
|
|
81
|
-
padding: 12px 24px;
|
|
82
|
-
text-align: center;
|
|
83
|
-
width: 100%;
|
|
84
|
-
cursor: pointer;
|
|
85
|
-
text-transform: uppercase;
|
|
86
|
-
}
|
|
87
|
-
#popup-body.overlay {
|
|
88
|
-
position: fixed;
|
|
89
|
-
z-index: 9998;
|
|
90
|
-
top: 0;
|
|
91
|
-
bottom: 0;
|
|
92
|
-
left: 0;
|
|
93
|
-
right: 0;
|
|
94
|
-
background: rgba(0, 0, 0, 0.7);
|
|
95
|
-
transition: opacity 200ms;
|
|
96
|
-
visibility: hidden;
|
|
97
|
-
opacity: 0;
|
|
98
|
-
}
|
|
99
|
-
#popup-wrapper {
|
|
100
|
-
margin: 70px auto;
|
|
101
|
-
z-index: 9999;
|
|
102
|
-
padding: 15px;
|
|
103
|
-
background: #fff;
|
|
104
|
-
border-radius: 5px;
|
|
105
|
-
max-width: 360px;
|
|
106
|
-
position: relative;
|
|
107
|
-
}
|
|
108
|
-
#popup-close {
|
|
109
|
-
position: absolute;
|
|
110
|
-
top: 5px;
|
|
111
|
-
right: 15px;
|
|
112
|
-
transition: all 200ms;
|
|
113
|
-
font-size: 30px;
|
|
114
|
-
font-weight: bold;
|
|
115
|
-
text-decoration: none;
|
|
116
|
-
color: #333;
|
|
117
|
-
cursor: pointer;
|
|
118
|
-
}
|
|
119
|
-
#popup-close:hover {
|
|
120
|
-
color: #d80606;
|
|
121
|
-
}
|
|
122
|
-
#popup-title {
|
|
123
|
-
margin: 0;
|
|
124
|
-
font-size: 20px;
|
|
125
|
-
max-width: 350px;
|
|
126
|
-
text-transform: uppercase;
|
|
127
|
-
}
|
|
128
|
-
#popup-text {
|
|
129
|
-
margin: 10px 0;
|
|
130
|
-
font-size: 14px;
|
|
131
|
-
}
|
|
132
|
-
#popup-form {
|
|
133
|
-
display: flex;
|
|
134
|
-
flex-direction: column;
|
|
135
|
-
gap: 10px;
|
|
136
|
-
}
|
|
137
|
-
#popup-form input {
|
|
138
|
-
padding: 0.475em 1em;
|
|
139
|
-
border: 1px solid #caced1;
|
|
140
|
-
border-radius: 0.25rem;
|
|
141
|
-
font-size: 1.15rem;
|
|
142
|
-
max-width: 100%;
|
|
143
|
-
}
|
|
144
|
-
#popup-form input::placeholder {
|
|
145
|
-
font-size: 1rem;
|
|
146
|
-
}
|
|
147
|
-
#popup-form button {
|
|
148
|
-
font-size: 0.85rem;
|
|
149
|
-
padding: 0.975em 1em;
|
|
150
|
-
font-weight: 600;
|
|
151
|
-
border: none;
|
|
152
|
-
text-transform: uppercase;
|
|
153
|
-
background: #aca475;
|
|
154
|
-
color: #fff;
|
|
155
|
-
cursor: pointer;
|
|
156
|
-
}
|
|
157
|
-
.custom-select {
|
|
158
|
-
position: relative;
|
|
159
|
-
}
|
|
160
|
-
.custom-select select {
|
|
161
|
-
appearance: none;
|
|
162
|
-
width: 100%;
|
|
163
|
-
font-size: 1.15rem;
|
|
164
|
-
padding: 0.475em 1em;
|
|
165
|
-
background-color: #fff;
|
|
166
|
-
border: 1px solid #caced1;
|
|
167
|
-
border-radius: 0.25rem;
|
|
168
|
-
color: #000;
|
|
169
|
-
cursor: pointer;
|
|
170
|
-
}
|
|
171
|
-
.custom-select::before,
|
|
172
|
-
.custom-select::after {
|
|
173
|
-
--size: 0.3rem;
|
|
174
|
-
content: "";
|
|
175
|
-
position: absolute;
|
|
176
|
-
right: 1rem;
|
|
177
|
-
pointer-events: none;
|
|
178
|
-
}
|
|
179
|
-
.custom-select::before {
|
|
180
|
-
border-left: var(--size) solid transparent;
|
|
181
|
-
border-right: var(--size) solid transparent;
|
|
182
|
-
border-bottom: var(--size) solid black;
|
|
183
|
-
top: 40%;
|
|
184
|
-
}
|
|
185
|
-
.custom-select::after {
|
|
186
|
-
border-left: var(--size) solid transparent;
|
|
187
|
-
border-right: var(--size) solid transparent;
|
|
188
|
-
border-top: var(--size) solid black;
|
|
189
|
-
top: 55%;
|
|
190
|
-
}
|
|
191
|
-
`;
|
|
192
|
-
|
|
193
|
-
const styleSheet = document.createElement("style");
|
|
194
|
-
styleSheet.type = "text/css";
|
|
195
|
-
styleSheet.innerText = styles;
|
|
196
|
-
document.head.appendChild(styleSheet);
|
|
197
|
-
|
|
198
|
-
// Create and append the overlay for the popup
|
|
199
|
-
const overlay = document.createElement("div");
|
|
200
|
-
overlay.innerHTML = `
|
|
201
|
-
<div id="popup-body" class="overlay">
|
|
202
|
-
<div id="popup-wrapper">
|
|
203
|
-
<h3 id="popup-title"></h3>
|
|
204
|
-
<span id="popup-close">×</span>
|
|
205
|
-
<div id="popup-text"></div>
|
|
206
|
-
<form id="popup-form">
|
|
207
|
-
<div class="custom-select">
|
|
208
|
-
<select name="select-size" required>
|
|
209
|
-
</select>
|
|
210
|
-
</div>
|
|
211
|
-
<input name="email" placeholder="Email" type="email" required />
|
|
212
|
-
</form>
|
|
213
|
-
</div>
|
|
214
|
-
</div>
|
|
215
|
-
`;
|
|
216
|
-
|
|
217
|
-
wrapper.appendChild(overlay);
|
|
218
|
-
|
|
219
|
-
const popupBody = document.getElementById("popup-body");
|
|
220
|
-
const popupClose = document.getElementById("popup-close");
|
|
221
|
-
const popupOpenButton = document.getElementById("popup-open");
|
|
222
|
-
const popupTitle = document.getElementById("popup-title");
|
|
223
|
-
const popupText = document.getElementById("popup-text");
|
|
224
|
-
const sizeSelect = document.querySelector("select[name='select-size']");
|
|
225
|
-
const form = overlay.querySelector("#popup-form");
|
|
226
|
-
|
|
227
|
-
if (!popupBody || !popupClose || !popupOpenButton || !popupTitle || !sizeSelect) return;
|
|
228
|
-
|
|
229
|
-
// Parse fields and type to be included in the form from data attribute
|
|
230
|
-
const fields = JSON.parse(popupOpenButton.getAttribute("data-fields") || '["email"]');
|
|
231
|
-
const type = popupOpenButton.getAttribute("data-type") || "notify-me";
|
|
232
|
-
const typeConfig = {
|
|
233
|
-
"notify-me": {
|
|
234
|
-
text: "Register to receive a notification as soon as this item is back in stock",
|
|
235
|
-
buttonText: "Notify me",
|
|
236
|
-
},
|
|
237
|
-
"coming-soon": {
|
|
238
|
-
text: "Register your interest to hear more about this item",
|
|
239
|
-
buttonText: "Register Interest",
|
|
240
|
-
},
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// Get product data from Shopify's global variable
|
|
244
|
-
const productData = window?.currentProduct;
|
|
245
|
-
|
|
246
|
-
// Map for form fields
|
|
247
|
-
popupText.innerText = typeConfig[type].text;
|
|
248
|
-
|
|
249
|
-
const fieldMap = {
|
|
250
|
-
email: `<input name="email" placeholder="Email" type="email" required />`,
|
|
251
|
-
mobile: `<input name="mobile" placeholder="Mobile" type="tel" required />`,
|
|
252
|
-
firstName: `<input name="firstName" placeholder="First name" type="text" required />`,
|
|
253
|
-
lastName: `<input name="lastName" placeholder="Last name" type="text" required />`,
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
// Add fields to the form based on the parsed fields
|
|
257
|
-
fields.forEach((field) => {
|
|
258
|
-
if (fieldMap[field]) {
|
|
259
|
-
form.insertAdjacentHTML("beforeend", fieldMap[field]);
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
form.insertAdjacentHTML("beforeend", `<div id="checkbox-wrapper"></div>`);
|
|
264
|
-
const checkboxWrapper = document.getElementById("checkbox-wrapper");
|
|
265
|
-
checkboxWrapper.insertAdjacentHTML("beforeend", `<input type="checkbox" name="mailList" id="mailList" />`);
|
|
266
|
-
checkboxWrapper.insertAdjacentHTML("beforeend", `<label for="mailList">Subscribe to our mailing list</label>`);
|
|
267
|
-
form.insertAdjacentHTML("beforeend", `<button type="submit">${typeConfig[type].buttonText}</button>`);
|
|
268
|
-
|
|
269
|
-
// Show/hide the popup
|
|
270
|
-
function showPopup() {
|
|
271
|
-
if (!productData) {
|
|
272
|
-
alert("Product data not found");
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
// Set the popup title and populate the size dropdown
|
|
276
|
-
popupTitle.innerHTML = productData.title;
|
|
277
|
-
productData.variants.forEach((variant) => {
|
|
278
|
-
const option = document.createElement("option");
|
|
279
|
-
option.value = variant.title;
|
|
280
|
-
option.textContent = variant.title;
|
|
281
|
-
sizeSelect.appendChild(option);
|
|
282
|
-
});
|
|
283
|
-
popupBody.style.visibility = "visible";
|
|
284
|
-
popupBody.style.opacity = 1;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
function hidePopup() {
|
|
288
|
-
popupBody.style.visibility = "hidden";
|
|
289
|
-
popupBody.style.opacity = 0;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
popupOpenButton.addEventListener("click", showPopup);
|
|
293
|
-
popupClose.addEventListener("click", hidePopup);
|
|
294
|
-
|
|
295
|
-
// Form submission handler
|
|
296
|
-
if (form) {
|
|
297
|
-
form.addEventListener("submit", function (event) {
|
|
298
|
-
event.preventDefault();
|
|
299
|
-
|
|
300
|
-
const selectedSize = sizeSelect.value;
|
|
301
|
-
const selectedVariant = productData.variants.find((variant) => variant.title === selectedSize);
|
|
302
|
-
|
|
303
|
-
if (selectedVariant) {
|
|
304
|
-
const formData = {
|
|
305
|
-
variantRef: selectedVariant.id,
|
|
306
|
-
email: form.querySelector("input[name='email']").value,
|
|
307
|
-
subscribe: form.querySelector("input[name='mailList']").checked,
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
if (type === "coming-soon") {
|
|
311
|
-
formData.comingSoon = true;
|
|
312
|
-
// formData.productRef = productData.id;
|
|
313
|
-
} else {
|
|
314
|
-
formData.notifyMe = true;
|
|
315
|
-
}
|
|
316
|
-
if (fields.includes("firstName")) {
|
|
317
|
-
formData.firstName = form.querySelector("input[name='firstName']").value;
|
|
318
|
-
}
|
|
319
|
-
if (fields.includes("lastName")) {
|
|
320
|
-
formData.lastName = form.querySelector("input[name='lastName']").value;
|
|
321
|
-
}
|
|
322
|
-
if (fields.includes("mobile")) {
|
|
323
|
-
formData.mobile = form.querySelector("input[name='mobile']").value;
|
|
324
|
-
// formData.phone = form.querySelector("input[name='mobile']").value;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
let url = `https://api.au-sandbox.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest`;
|
|
328
|
-
|
|
329
|
-
fetch(url, {
|
|
330
|
-
method: "POST",
|
|
331
|
-
headers: {
|
|
332
|
-
"Content-Type": "application/json",
|
|
333
|
-
Authorization: ACCESS_TOKEN,
|
|
334
|
-
"X-Twc-Tenant": TENANT_ID,
|
|
335
|
-
},
|
|
336
|
-
body: JSON.stringify(formData),
|
|
337
|
-
})
|
|
338
|
-
.then((response) => {
|
|
339
|
-
if (response.ok) {
|
|
340
|
-
alert("Form submitted");
|
|
341
|
-
hidePopup();
|
|
342
|
-
} else {
|
|
343
|
-
alert("Form submission failed");
|
|
344
|
-
}
|
|
345
|
-
})
|
|
346
|
-
.catch((error) => {
|
|
347
|
-
console.error("Error submitting form:", error);
|
|
348
|
-
alert("Form submission failed");
|
|
349
|
-
});
|
|
350
|
-
} else {
|
|
351
|
-
alert("Selected variant not found");
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
```
|
|
358
|
-
|
|
359
63
|
Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
|
|
360
64
|
Replace `TENANT_ID` with your actual tenant to authenticate API requests.
|
package/index.js
CHANGED
|
@@ -3,6 +3,157 @@ const ACCESS_TOKEN =
|
|
|
3
3
|
'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJRWlJkS3JabXJmMEk3WkhXRUtqNWRLTEhQanFubWJFeV9iNmpSbHdya1drIn0.eyJleHAiOjE3MjMwMzI3NzIsImlhdCI6MTcyMzAyOTE3MiwianRpIjoiNDJiNGYwM2QtMDNiNS00NmZlLTk5YmItZDQ2NTdhNjk5NGNiIiwiaXNzIjoiaHR0cHM6Ly9hdXRoLmF1LWF3cy50aGV3aXNobGlzdC5pby9hdXRoL3JlYWxtcy90d2NNYWluIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6IjI2YTIyNTAyLWRhNzQtNDhkMC1iZWFiLTgzY2E0YTlmMDdlOSIsInR5cCI6IkJlYXJlciIsImF6cCI6InR3Yy1wb3MtY2xpZW50Iiwic2Vzc2lvbl9zdGF0ZSI6IjQxYWQwMDc4LWVmYTItNGVjMi1hM2I2LTIzYjBkNDM3YjEzOCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiaHR0cHM6Ly9sb2NhbGhvc3QiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbInR3Yy1wb3MtdXNlciIsIm9mZmxpbmVfYWNjZXNzIiwidHdjLXN0b3JlLW93bmVyIiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6InRlbmFudGlkIHN0b3JlIHByb2ZpbGUgZW1haWwiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsInRlbmFudGlkIjoidmlrdG9yaWEtd29vZHMiLCJuYW1lIjoiTWF0dCBIYW1wc2hpcmUiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJtYXR0QHRoZXdpc2hsaXN0LmlvIiwic3RvcmUiOiIyMDUiLCJnaXZlbl9uYW1lIjoiTWF0dCIsImZhbWlseV9uYW1lIjoiSGFtcHNoaXJlIiwiZW1haWwiOiJtYXR0QHRoZXdpc2hsaXN0LmlvIn0.iZkMgwH74njjXUWvImkJomHYr91Lr8ZGrZGwslEGcV3vbNuoNc5CocvNWW476o-LoSh-LsKf-MLiYN1XvOuPDF3fGoGCEbMh6_M0RJcrhVWogkj81fx4ukvDPCFIjgoDCV9WIuehV9dsSWa7E0irZeE6MUVhLwRIaTzKtxgzUUKrAqBtI_HKpyo8TUGQBiYlrc85QFUyuoKbKg-QaRn_SObRLDB8ooIBJvIlgklXQt1ZYBM2HUOc5L1bAQwfzcrWEvl6eYiQHXCSPqS0rPGoaGC6v5ydBo9VMxtVHGladDHLrO3Gt2BnIGMBoYrKTAmt7j0KABwPyB3CmAIwj_pOBQ'; // Replace `ACCESS_TOKEN` with your actual access token to authenticate API requests.
|
|
4
4
|
const TENANT_ID = 'victoria-woods'; // Replace `TENANT_ID` with your actual tenant ID.
|
|
5
5
|
|
|
6
|
+
const COUNTRY_CODES = [
|
|
7
|
+
{ code: 'AF', name: 'Afghanistan' }, { code: 'AX', name: 'Åland Islands' },
|
|
8
|
+
{ code: 'AL', name: 'Albania' }, { code: 'DZ', name: 'Algeria' },
|
|
9
|
+
{ code: 'AS', name: 'American Samoa' }, { code: 'AD', name: 'Andorra' },
|
|
10
|
+
{ code: 'AO', name: 'Angola' }, { code: 'AI', name: 'Anguilla' },
|
|
11
|
+
{ code: 'AG', name: 'Antigua and Barbuda' }, { code: 'AR', name: 'Argentina' },
|
|
12
|
+
{ code: 'AM', name: 'Armenia' }, { code: 'AW', name: 'Aruba' },
|
|
13
|
+
{ code: 'AU', name: 'Australia' }, { code: 'AT', name: 'Austria' },
|
|
14
|
+
{ code: 'AZ', name: 'Azerbaijan' }, { code: 'BS', name: 'Bahamas' },
|
|
15
|
+
{ code: 'BH', name: 'Bahrain' }, { code: 'BD', name: 'Bangladesh' },
|
|
16
|
+
{ code: 'BB', name: 'Barbados' }, { code: 'BY', name: 'Belarus' },
|
|
17
|
+
{ code: 'BE', name: 'Belgium' }, { code: 'BZ', name: 'Belize' },
|
|
18
|
+
{ code: 'BJ', name: 'Benin' }, { code: 'BM', name: 'Bermuda' },
|
|
19
|
+
{ code: 'BT', name: 'Bhutan' }, { code: 'BO', name: 'Bolivia' },
|
|
20
|
+
{ code: 'BA', name: 'Bosnia and Herzegovina' }, { code: 'BW', name: 'Botswana' },
|
|
21
|
+
{ code: 'BR', name: 'Brazil' }, { code: 'BN', name: 'Brunei' },
|
|
22
|
+
{ code: 'BG', name: 'Bulgaria' }, { code: 'BF', name: 'Burkina Faso' },
|
|
23
|
+
{ code: 'BI', name: 'Burundi' }, { code: 'CV', name: 'Cabo Verde' },
|
|
24
|
+
{ code: 'KH', name: 'Cambodia' }, { code: 'CM', name: 'Cameroon' },
|
|
25
|
+
{ code: 'CA', name: 'Canada' }, { code: 'KY', name: 'Cayman Islands' },
|
|
26
|
+
{ code: 'CF', name: 'Central African Republic' }, { code: 'TD', name: 'Chad' },
|
|
27
|
+
{ code: 'CL', name: 'Chile' }, { code: 'CN', name: 'China' },
|
|
28
|
+
{ code: 'CO', name: 'Colombia' }, { code: 'KM', name: 'Comoros' },
|
|
29
|
+
{ code: 'CG', name: 'Congo' }, { code: 'CD', name: 'Congo, DR' },
|
|
30
|
+
{ code: 'CK', name: 'Cook Islands' }, { code: 'CR', name: 'Costa Rica' },
|
|
31
|
+
{ code: 'HR', name: 'Croatia' }, { code: 'CU', name: 'Cuba' },
|
|
32
|
+
{ code: 'CW', name: 'Curaçao' }, { code: 'CY', name: 'Cyprus' },
|
|
33
|
+
{ code: 'CZ', name: 'Czech Republic' }, { code: 'DK', name: 'Denmark' },
|
|
34
|
+
{ code: 'DJ', name: 'Djibouti' }, { code: 'DM', name: 'Dominica' },
|
|
35
|
+
{ code: 'DO', name: 'Dominican Republic' }, { code: 'EC', name: 'Ecuador' },
|
|
36
|
+
{ code: 'EG', name: 'Egypt' }, { code: 'SV', name: 'El Salvador' },
|
|
37
|
+
{ code: 'GQ', name: 'Equatorial Guinea' }, { code: 'ER', name: 'Eritrea' },
|
|
38
|
+
{ code: 'EE', name: 'Estonia' }, { code: 'SZ', name: 'Eswatini' },
|
|
39
|
+
{ code: 'ET', name: 'Ethiopia' }, { code: 'FO', name: 'Faroe Islands' },
|
|
40
|
+
{ code: 'FJ', name: 'Fiji' }, { code: 'FI', name: 'Finland' },
|
|
41
|
+
{ code: 'FR', name: 'France' }, { code: 'GF', name: 'French Guiana' },
|
|
42
|
+
{ code: 'PF', name: 'French Polynesia' }, { code: 'GA', name: 'Gabon' },
|
|
43
|
+
{ code: 'GM', name: 'Gambia' }, { code: 'GE', name: 'Georgia' },
|
|
44
|
+
{ code: 'DE', name: 'Germany' }, { code: 'GH', name: 'Ghana' },
|
|
45
|
+
{ code: 'GI', name: 'Gibraltar' }, { code: 'GR', name: 'Greece' },
|
|
46
|
+
{ code: 'GL', name: 'Greenland' }, { code: 'GD', name: 'Grenada' },
|
|
47
|
+
{ code: 'GP', name: 'Guadeloupe' }, { code: 'GU', name: 'Guam' },
|
|
48
|
+
{ code: 'GT', name: 'Guatemala' }, { code: 'GN', name: 'Guinea' },
|
|
49
|
+
{ code: 'GW', name: 'Guinea-Bissau' }, { code: 'GY', name: 'Guyana' },
|
|
50
|
+
{ code: 'HT', name: 'Haiti' }, { code: 'HN', name: 'Honduras' },
|
|
51
|
+
{ code: 'HK', name: 'Hong Kong' }, { code: 'HU', name: 'Hungary' },
|
|
52
|
+
{ code: 'IS', name: 'Iceland' }, { code: 'IN', name: 'India' },
|
|
53
|
+
{ code: 'ID', name: 'Indonesia' }, { code: 'IR', name: 'Iran' },
|
|
54
|
+
{ code: 'IQ', name: 'Iraq' }, { code: 'IE', name: 'Ireland' },
|
|
55
|
+
{ code: 'IM', name: 'Isle of Man' }, { code: 'IL', name: 'Israel' },
|
|
56
|
+
{ code: 'IT', name: 'Italy' }, { code: 'JM', name: 'Jamaica' },
|
|
57
|
+
{ code: 'JP', name: 'Japan' }, { code: 'JE', name: 'Jersey' },
|
|
58
|
+
{ code: 'JO', name: 'Jordan' }, { code: 'KZ', name: 'Kazakhstan' },
|
|
59
|
+
{ code: 'KE', name: 'Kenya' }, { code: 'KI', name: 'Kiribati' },
|
|
60
|
+
{ code: 'KR', name: 'Korea, South' }, { code: 'XK', name: 'Kosovo' },
|
|
61
|
+
{ code: 'KW', name: 'Kuwait' }, { code: 'KG', name: 'Kyrgyzstan' },
|
|
62
|
+
{ code: 'LA', name: 'Laos' }, { code: 'LV', name: 'Latvia' },
|
|
63
|
+
{ code: 'LB', name: 'Lebanon' }, { code: 'LS', name: 'Lesotho' },
|
|
64
|
+
{ code: 'LR', name: 'Liberia' }, { code: 'LY', name: 'Libya' },
|
|
65
|
+
{ code: 'LI', name: 'Liechtenstein' }, { code: 'LT', name: 'Lithuania' },
|
|
66
|
+
{ code: 'LU', name: 'Luxembourg' }, { code: 'MO', name: 'Macao' },
|
|
67
|
+
{ code: 'MG', name: 'Madagascar' }, { code: 'MW', name: 'Malawi' },
|
|
68
|
+
{ code: 'MY', name: 'Malaysia' }, { code: 'MV', name: 'Maldives' },
|
|
69
|
+
{ code: 'ML', name: 'Mali' }, { code: 'MT', name: 'Malta' },
|
|
70
|
+
{ code: 'MH', name: 'Marshall Islands' }, { code: 'MQ', name: 'Martinique' },
|
|
71
|
+
{ code: 'MR', name: 'Mauritania' }, { code: 'MU', name: 'Mauritius' },
|
|
72
|
+
{ code: 'MX', name: 'Mexico' }, { code: 'FM', name: 'Micronesia' },
|
|
73
|
+
{ code: 'MD', name: 'Moldova' }, { code: 'MC', name: 'Monaco' },
|
|
74
|
+
{ code: 'MN', name: 'Mongolia' }, { code: 'ME', name: 'Montenegro' },
|
|
75
|
+
{ code: 'MS', name: 'Montserrat' }, { code: 'MA', name: 'Morocco' },
|
|
76
|
+
{ code: 'MZ', name: 'Mozambique' }, { code: 'MM', name: 'Myanmar' },
|
|
77
|
+
{ code: 'NA', name: 'Namibia' }, { code: 'NR', name: 'Nauru' },
|
|
78
|
+
{ code: 'NP', name: 'Nepal' }, { code: 'NL', name: 'Netherlands' },
|
|
79
|
+
{ code: 'NC', name: 'New Caledonia' }, { code: 'NZ', name: 'New Zealand' },
|
|
80
|
+
{ code: 'NI', name: 'Nicaragua' }, { code: 'NE', name: 'Niger' },
|
|
81
|
+
{ code: 'NG', name: 'Nigeria' }, { code: 'NU', name: 'Niue' },
|
|
82
|
+
{ code: 'MK', name: 'North Macedonia' }, { code: 'NO', name: 'Norway' },
|
|
83
|
+
{ code: 'OM', name: 'Oman' }, { code: 'PK', name: 'Pakistan' },
|
|
84
|
+
{ code: 'PW', name: 'Palau' }, { code: 'PS', name: 'Palestine' },
|
|
85
|
+
{ code: 'PA', name: 'Panama' }, { code: 'PG', name: 'Papua New Guinea' },
|
|
86
|
+
{ code: 'PY', name: 'Paraguay' }, { code: 'PE', name: 'Peru' },
|
|
87
|
+
{ code: 'PH', name: 'Philippines' }, { code: 'PL', name: 'Poland' },
|
|
88
|
+
{ code: 'PT', name: 'Portugal' }, { code: 'PR', name: 'Puerto Rico' },
|
|
89
|
+
{ code: 'QA', name: 'Qatar' }, { code: 'RE', name: 'Réunion' },
|
|
90
|
+
{ code: 'RO', name: 'Romania' },
|
|
91
|
+
{ code: 'RW', name: 'Rwanda' }, { code: 'KN', name: 'Saint Kitts and Nevis' },
|
|
92
|
+
{ code: 'LC', name: 'Saint Lucia' }, { code: 'VC', name: 'Saint Vincent and the Grenadines' },
|
|
93
|
+
{ code: 'WS', name: 'Samoa' }, { code: 'SM', name: 'San Marino' },
|
|
94
|
+
{ code: 'SA', name: 'Saudi Arabia' }, { code: 'SN', name: 'Senegal' },
|
|
95
|
+
{ code: 'RS', name: 'Serbia' }, { code: 'SC', name: 'Seychelles' },
|
|
96
|
+
{ code: 'SL', name: 'Sierra Leone' }, { code: 'SG', name: 'Singapore' },
|
|
97
|
+
{ code: 'SK', name: 'Slovakia' }, { code: 'SI', name: 'Slovenia' },
|
|
98
|
+
{ code: 'SB', name: 'Solomon Islands' }, { code: 'SO', name: 'Somalia' },
|
|
99
|
+
{ code: 'ZA', name: 'South Africa' }, { code: 'SS', name: 'South Sudan' },
|
|
100
|
+
{ code: 'ES', name: 'Spain' }, { code: 'LK', name: 'Sri Lanka' },
|
|
101
|
+
{ code: 'SD', name: 'Sudan' }, { code: 'SR', name: 'Suriname' },
|
|
102
|
+
{ code: 'SE', name: 'Sweden' }, { code: 'CH', name: 'Switzerland' },
|
|
103
|
+
{ code: 'SY', name: 'Syria' }, { code: 'TW', name: 'Taiwan' },
|
|
104
|
+
{ code: 'TJ', name: 'Tajikistan' }, { code: 'TZ', name: 'Tanzania' },
|
|
105
|
+
{ code: 'TH', name: 'Thailand' }, { code: 'TL', name: 'Timor-Leste' },
|
|
106
|
+
{ code: 'TG', name: 'Togo' }, { code: 'TO', name: 'Tonga' },
|
|
107
|
+
{ code: 'TT', name: 'Trinidad and Tobago' }, { code: 'TN', name: 'Tunisia' },
|
|
108
|
+
{ code: 'TR', name: 'Turkey' }, { code: 'TM', name: 'Turkmenistan' },
|
|
109
|
+
{ code: 'TC', name: 'Turks and Caicos Islands' }, { code: 'TV', name: 'Tuvalu' },
|
|
110
|
+
{ code: 'UG', name: 'Uganda' }, { code: 'UA', name: 'Ukraine' },
|
|
111
|
+
{ code: 'AE', name: 'United Arab Emirates' }, { code: 'GB', name: 'United Kingdom' },
|
|
112
|
+
{ code: 'US', name: 'United States' }, { code: 'UY', name: 'Uruguay' },
|
|
113
|
+
{ code: 'UZ', name: 'Uzbekistan' }, { code: 'VU', name: 'Vanuatu' },
|
|
114
|
+
{ code: 'VE', name: 'Venezuela' }, { code: 'VN', name: 'Vietnam' },
|
|
115
|
+
{ code: 'VG', name: 'Virgin Islands, British' }, { code: 'VI', name: 'Virgin Islands, U.S.' },
|
|
116
|
+
{ code: 'YE', name: 'Yemen' }, { code: 'ZM', name: 'Zambia' },
|
|
117
|
+
{ code: 'ZW', name: 'Zimbabwe' },
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
// Detect country/province/market context using priority fallback chain
|
|
121
|
+
function detectCountryContext() {
|
|
122
|
+
const ctx = { countryCode: null, provinceCode: null, marketId: null };
|
|
123
|
+
|
|
124
|
+
// Priority 1: Shopify localization/country context
|
|
125
|
+
const shopify = window.Shopify;
|
|
126
|
+
if (shopify) {
|
|
127
|
+
if (typeof shopify.country === 'string') ctx.countryCode = shopify.country;
|
|
128
|
+
const mkt = shopify.markets?.currentMarket;
|
|
129
|
+
if (mkt) {
|
|
130
|
+
if (mkt.countryCode) ctx.countryCode = mkt.countryCode;
|
|
131
|
+
if (mkt.id != null) ctx.marketId = String(mkt.id);
|
|
132
|
+
}
|
|
133
|
+
if (!ctx.countryCode && typeof shopify.locale === 'string') {
|
|
134
|
+
const parts = shopify.locale.split('-');
|
|
135
|
+
if (parts.length > 1) ctx.countryCode = parts[parts.length - 1].toUpperCase();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Priority 2: Existing customer shipping country
|
|
140
|
+
if (!ctx.countryCode || !ctx.provinceCode) {
|
|
141
|
+
const addr = window.customer?.default_address;
|
|
142
|
+
if (addr) {
|
|
143
|
+
if (!ctx.countryCode && addr.country_code) ctx.countryCode = addr.country_code;
|
|
144
|
+
if (!ctx.provinceCode && addr.province_code) ctx.provinceCode = addr.province_code;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Priority 3: Browser locale fallback
|
|
149
|
+
if (!ctx.countryCode) {
|
|
150
|
+
const parts = (navigator.language || '').split('-');
|
|
151
|
+
if (parts.length > 1) ctx.countryCode = parts[parts.length - 1].toUpperCase();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return ctx;
|
|
155
|
+
}
|
|
156
|
+
|
|
6
157
|
document.addEventListener('DOMContentLoaded', function () {
|
|
7
158
|
const wrapper = document.getElementById('notification-widget');
|
|
8
159
|
if (!wrapper) return;
|
|
@@ -196,14 +347,25 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
196
347
|
// Get product data from Shopify's global variable
|
|
197
348
|
const productData = window?.currentProduct;
|
|
198
349
|
|
|
350
|
+
const countryCtx = detectCountryContext();
|
|
351
|
+
const resolvedMarketId =
|
|
352
|
+
popupOpenButton.getAttribute('data-market-id') || countryCtx.marketId;
|
|
353
|
+
|
|
199
354
|
// Map for form fields
|
|
200
355
|
popupText.innerText = typeConfig[type].text;
|
|
201
356
|
|
|
357
|
+
const countryOptions = COUNTRY_CODES.map(
|
|
358
|
+
(c) =>
|
|
359
|
+
`<option value="${c.code}"${c.code === countryCtx.countryCode ? ' selected' : ''}>${c.name}</option>`,
|
|
360
|
+
).join('');
|
|
361
|
+
|
|
202
362
|
const fieldMap = {
|
|
203
363
|
email: `<input name="email" placeholder="Email" type="email" required />`,
|
|
204
364
|
mobile: `<input name="mobile" placeholder="Mobile" type="tel" required />`,
|
|
205
365
|
firstName: `<input name="firstName" placeholder="First name" type="text" required />`,
|
|
206
366
|
lastName: `<input name="lastName" placeholder="Last name" type="text" required />`,
|
|
367
|
+
countryCode: `<div class="custom-select"><select name="countryCode"><option value="">Select country</option>${countryOptions}</select></div>`,
|
|
368
|
+
provinceCode: `<input name="provinceCode" placeholder="State / Province code" type="text" value="${countryCtx.provinceCode || ''}" />`,
|
|
207
369
|
};
|
|
208
370
|
|
|
209
371
|
// Add fields to the form based on the parsed fields
|
|
@@ -293,6 +455,23 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
|
293
455
|
// formData.phone = form.querySelector("input[name='mobile']").value;
|
|
294
456
|
}
|
|
295
457
|
|
|
458
|
+
// Country / province / market — manual fields take precedence over auto-detected values
|
|
459
|
+
if (fields.includes('countryCode')) {
|
|
460
|
+
const selected = form.querySelector("select[name='countryCode']").value;
|
|
461
|
+
if (selected) formData.countryCode = selected;
|
|
462
|
+
} else if (countryCtx.countryCode) {
|
|
463
|
+
formData.countryCode = countryCtx.countryCode;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (fields.includes('provinceCode')) {
|
|
467
|
+
const val = form.querySelector("input[name='provinceCode']").value;
|
|
468
|
+
if (val) formData.provinceCode = val;
|
|
469
|
+
} else if (countryCtx.provinceCode) {
|
|
470
|
+
formData.provinceCode = countryCtx.provinceCode;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (resolvedMarketId) formData.marketId = resolvedMarketId;
|
|
474
|
+
|
|
296
475
|
let url = `https://api.au-sandbox.thewishlist.io/services/wsservice/api/wishlist/items/customerInterest`;
|
|
297
476
|
|
|
298
477
|
fetch(url, {
|