-
Notifications
You must be signed in to change notification settings - Fork 0
/
createorder.js
195 lines (183 loc) · 5.9 KB
/
createorder.js
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
const newVariantPrice = (document.getElementById("product-variant-price") || {})
.value;
const onePriceQty = (document.getElementById("product_price_hidden") || {})
.value;
if (onePriceQty > 0) {
const container = document.getElementById("one_price_container");
container.style.display = "block";
const input = container.querySelector("input");
input.setAttribute("required", "");
function changePrice(evalue) {
const tot = document.getElementById("product_price_hidden").value * evalue;
const total = `That's ₦${tot.toLocaleString()}`;
document.querySelector("#show_Product_total").value = total;
}
document
.querySelector("#show_Product_Quantity")
.addEventListener("click", (e) => {
const evalue = e.target.value;
changePrice(evalue);
});
document
.querySelector("#show_Product_Quantity")
.addEventListener("keyup", (e) => {
const evalue = e.target.value;
changePrice(evalue);
});
} else {
const selectPromoPrice = document.getElementById("selectPromoPrice");
const container = document.getElementById("variant_price_Quanity_container");
if (container.style.display === "none") {
container.style.display = "block";
const select = container.querySelector("select");
select.setAttribute("required", "");
const PromoQtyArray = newVariantPrice.split(",");
const newPromoQtyArray = PromoQtyArray.filter((e) => e !== " 0 = 0 Naira");
for (var i = 0; i < newPromoQtyArray.length; i++) {
var opt = newPromoQtyArray[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
selectPromoPrice.appendChild(el);
}
}
}
const newVariantColours = (
document.getElementById("product-variant-color") || {}
).value;
if (newVariantColours != "") {
const container = document.getElementById("variant_colours_container");
if (container.style.display === "none") {
container.style.display = "block";
const select = container.querySelector("select");
select.setAttribute("required", "");
const selectColours = document.getElementById("selectColours");
const coloursOptions = newVariantColours.split(",");
for (var i = 0; i < coloursOptions.length; i++) {
var opt = coloursOptions[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
selectColours.appendChild(el);
}
}
}
const newVariantSizes = (document.getElementById("product-variant-size") || {})
.value;
if (newVariantSizes != "") {
const container = document.getElementById("variant_size_container");
if (container.style.display === "none") {
container.style.display = "block";
const select = container.querySelector("select");
select.setAttribute("required", "");
const selectSizes = document.getElementById("selectSizes");
const sizesOptions = newVariantSizes.split(",");
for (var i = 0; i < sizesOptions.length; i++) {
var opt = sizesOptions[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
selectSizes.appendChild(el);
}
}
}
const creaEmbedOrderForm = document.querySelector(".embed-order-form");
if (creaEmbedOrderForm)
creaEmbedOrderForm.addEventListener("submit", (e) => {
e.preventDefault();
const submitButton = e.submitter;
const email = (document.getElementById("embedEmail") || {}).value;
const name = (document.getElementById("embedName") || {}).value;
const address = (document.getElementById("embedAddress") || {}).value;
const state = (document.getElementById("embedState") || {}).value;
const area = (document.getElementById("embedArea") || {}).value;
const phone = (document.getElementById("embedPhone") || {}).value;
const altphone = (document.getElementById("embedPhone2") || {}).value;
const qty = (document.getElementById("embedQty") || {}).value;
const size = (selectSizes.options[selectSizes.selectedIndex] || {}).value;
const colour = (selectColours.options[selectColours.selectedIndex] || {})
.value;
const product = (document.getElementById("embedProduct") || {}).value;
const businessAccount = (
document.getElementById("embedBusinessAccount") || {}
).value;
const onePriceQty = (document.getElementById("product_price_hidden") || {})
.value;
if (onePriceQty > 0) {
var productEmbedQty = document.getElementById("show_Product_Quantity")
.value;
const total = document
.getElementById("show_Product_total")
.value.replace("₦", " ")
.replace(/\D/g, "");
var productEmbedTotal = parseInt(total);
} else {
var productQtyValue = document.getElementById("selectPromoPrice").value;
var productEmbedQty = productQtyValue
.split("=")[0]
.replace(/^\s+|\s+$/gm, "");
const total = productQtyValue.split("=")[1].split(" ")[1];
var productEmbedTotal = parseInt(total);
}
createOrderAPI(
businessAccount,
product,
name,
email,
address,
state,
area,
phone,
altphone,
productEmbedQty,
productEmbedTotal,
colour,
size,
submitButton
);
});
const createOrderAPI = async (
businessAccount,
product,
name,
email,
address,
state,
area,
phone,
altphone,
qty,
total,
colour,
size,
submitButton
) => {
try {
const res = await axios({
method: "POST",
url: "https://rirapay.com/api/v1/orders",
data: {
businessAccount,
product,
name,
email,
address,
state,
area,
phone,
altphone,
qty,
total,
colour,
size,
},
});
const orderId = res.data.data.newOrder._id;
if (res.data.status === "success") {
window.location.assign(`https://rirapay.com/orderInfo/${orderId}`);
}
} catch (err) {
alert(err.response.data.message);
console.log(err);
}
};