-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcartscript.js
195 lines (141 loc) · 9.6 KB
/
cartscript.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
let oldArr = [{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/1000x1000-hero_1_500x.jpg?v=1620801652", "name": "Lakme 9TO5 VITAMIN C + SKINCARE VALUE SET", "currentPrice": "999", "oldPrice": "1297", "discoutPrice": "23% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/img1_3_1_500x.jpg?v=1620910668", "name": "Lakme GREEN TEA ESSENTIALS KIT", "currentPrice": "699", "oldPrice": "847", "discoutPrice": "17% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/Lakme9to5Primer_MatteLipColorRedLetter_500x.jpg?v=1598243140", "name": "Lakme 9 to 5 Primer + Matte Lip Color", "currentPrice": "300", "oldPrice": "500", "discoutPrice": "40% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/24544_H-8901030758850_3e09b888-1276-44a2-9665-fa293cbd5d3_500x.jpg?v=1601470864", "name": "Lakme Forever Matte Liquid Lip Color", "currentPrice": "295", "oldPrice": null, "discoutPrice": null, "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/LakmeAbsoluteMatteUltimateLipColorwithArganOilPetalPink_41b560b6-3f0d-47b2-bfd5-075cf7bc0934_500x.jpg?v=1599200805", "name": "Lakme Absolute Matte Ultimate Lip Color with Argan Oil", "currentPrice": "800", "oldPrice": null, "discoutPrice": null, "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/Blackjack_500x.png?v=1598528925", "name": "Lakme Absolute Gel Stylist Nail Color", "currentPrice": "250", "oldPrice": null, "discoutPrice": null, "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/M2_500x.jpg?v=1601551735", "name": "Lakme Color Crush Nail Art", "currentPrice": "155", "oldPrice": null, "discoutPrice": null, "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/Lakme9to5CCComplexionCareCream_9gmBeige_500x.jpg?v=1598101798", "name": "Lakme 9 to 5 CC Complexion Care Cream, 9gm", "currentPrice": "99", "oldPrice": null, "discoutPrice": null, "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/2-fop-smokin-glam_1_500x.jpg?v=1603894790", "name": "Lakme Absolute Spotlight Eyeshadow Palette", "currentPrice": "597", "oldPrice": "995", "discoutPrice": "40% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/Pinks-N238_500x.jpg?v=1603185561", "name": "Lakme True Wear Nail Color", "currentPrice": "88", "oldPrice": "110", "discoutPrice": "20% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/24329_S1-8901030719165_500x.jpg?v=1633765701", "name": "Lakme Insta Eye Liner", "currentPrice": "130", "oldPrice": null, "discoutPrice": null, "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/24453_S1-8901030742804_500x.jpg?v=1611756792", "name": "Lakme 9 to 5 Primer + Matte Perfect Cover Foundation", "currentPrice": "352", "oldPrice": "475", "discoutPrice": "26% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/24704_H-8901030776533_500x.jpg?v=1601452154", "name": "Lakme Cushion Matte", "currentPrice": "275", "oldPrice": null, "discoutPrice": null, "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/Blue-Scape_500x.jpg?v=1628509200", "name": "Lakme 9 to 5 Primer + Gloss Nail Color", "currentPrice": "144", "oldPrice": "180", "discoutPrice": "20% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/LakmeLipLoveChapstickCherry_500x.jpg?v=1598359759", "name": "Lakme Lip Love Chapstick", "currentPrice": "150", "oldPrice": null, "discoutPrice": null, "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/red-carnival_500x.jpg?v=1602153688", "name": "Lakme Absolute 3D Lipstick", "currentPrice": "640", "oldPrice": "800", "discoutPrice": "20% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/LakmeSunExpertUltraMatteSPF40PA_Compact-7g_500x.jpg?v=1598361828", "name": "Lakme Sun Expert Ultra Matte SPF 40 PA+++ Compact - 7 g", "currentPrice": "196", "oldPrice": "230", "discoutPrice": "15% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/Lakme9to5NaturaleAloeAquaGel_500x.png?v=1598252908", "name": "Lakme 9to5 Naturale Aloe Aqua Gel", "currentPrice": "160", "oldPrice": "200", "discoutPrice": "20% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/LakmeAbsoluteWhiteIntenseWet_DryCompactGoldenLight_500x.jpg?v=1603787165", "name": "Lakme Absolute White Intense Wet & Dry Compact", "currentPrice": "742", "oldPrice": "800", "discoutPrice": "7% off", "isSoldOut": null},
{"image": "https://cdn.shopify.com/s/files/1/0014/3514/0183/products/Shade_PM14_500x.jpg?v=1603456524", "name": "Lakme Enrich Matte Lipstick", "currentPrice": "295", "oldPrice": null, "discoutPrice": null, "isSoldOut": null}];
let arr = JSON.parse(localStorage.getItem('data'));
document.querySelector('#cross').addEventListener('click', crossDis);
function crossDis() {
document.querySelector('.fixed').classList.add('display')
}
if(arr = []) {
arr.push(...oldArr);
localStorage.setItem('data', JSON.stringify(arr));
}
if(arr.length > 0) {
var disable = document.querySelector('#cart-img');
var disable2 = document.querySelector('.belowCart');
disable2.setAttribute('class', 'notshow')
disable.setAttribute('class', 'notshow')
var active = document.querySelector('.box3');
active.setAttribute('class', 'show');
addingData(arr);
console.log(arr);
function addingData() {
console.log(arr)
let sum = 0;
let oldSum = 0;
arr.map(function(elm, ind) {
sum += Number(elm.currentPrice);
oldSum += Number(elm.oldPrice);
document.querySelector('.savings').textContent = '₹'+' '+(sum - oldSum);
document.querySelector('.totalPrice').textContent = '₹'+' '+sum;
if(sum > 200) {
document.querySelector('.shipping').textContent = '₹'+' '+'120';
document.querySelector('.totalPrice2').textContent = '₹'+' '+(120+sum);
} else if(sum > 700) {
document.querySelector('.shipping').textContent = '₹'+' '+'43';
document.querySelector('.totalPrice2').textContent = '₹'+' '+(43+sum);
}
var section2 = document.createElement('section');
section2.setAttribute('id', 'product');
var div1 = document.createElement('div');
div1.setAttribute('class', 'productbox div1');
var div2 = document.createElement('div');
var div2p = document.createElement('p');
div2p.textContent = elm.name;
div2.append(div2p)
div2.setAttribute('class', 'productbox div2');
var div4 = document.createElement('div');
div4.setAttribute('class', 'productbox');
div4.textContent = '₹' + elm.currentPrice;
var div5 = document.createElement('div');
div5.setAttribute('class', 'productbox div5');
if(elm.oldPrice != null) {
div5.textContent = '₹' + elm.oldPrice;
}
var div6 = document.createElement('div');
div6.setAttribute('class', 'productbox div6');
var div7 = document.createElement('div');
div7.setAttribute('class', 'productbox');
document.querySelector('.box2').append(section2);
section2.append(div1, div2, div4, div5, div6, div7);
var imgProduct = document.createElement('img');
imgProduct.setAttribute('id', 'imgProduct');
imgProduct.setAttribute('src', elm.image);
div1.append(imgProduct);
let div6Box1 = document.createElement('div');
div6Box1.textContent = '-'
div6Box1.setAttribute('class', 'div6Box1')
let div6Box2 = document.createElement('div');
div6Box2.setAttribute('class', 'div6Box2')
let div6Box3 = document.createElement('div');
div6Box3.textContent = '+';
div6Box3.setAttribute('class', 'div6Box3')
div6.append(div6Box1, div6Box2, div6Box3);
//add cart button
var cartValue = 1;
// div6.div6Box1.textContent = '+'
div6Box3.addEventListener('click', plusProduct);
function plusProduct() {
cartValue++;
div6Box2.textContent = cartValue;
if(cartValue > 1) {
sum += Number(elm.currentPrice);
oldSum += Number(elm.oldPrice);
document.querySelector('.savings').textContent = '₹'+' '+(sum - oldSum);
document.querySelector('.totalPrice').textContent = '₹'+' '+sum;
if(sum > 200) {
document.querySelector('.shipping').textContent = '₹'+' '+'120';
document.querySelector('.totalPrice2').textContent = '₹'+' '+(120+sum);
} else if(sum > 700) {
document.querySelector('.shipping').textContent = '₹'+' '+'43';
document.querySelector('.totalPrice2').textContent = '₹'+' '+(43+sum);
}
}
}
div6Box2.textContent = cartValue;
div6Box1.addEventListener('click', minusProduct);
function minusProduct() {
cartValue = cartValue -1;
div6Box2.textContent = cartValue;
// if(cartValue >= 0) {
sum = sum - Number(elm.currentPrice);
oldSum = oldSum - Number(elm.oldPrice);
document.querySelector('.savings').textContent = '₹'+' '+(sum - oldSum);
document.querySelector('.totalPrice').textContent = '₹'+' '+sum;
document.querySelector('.totalPrice2').textContent = '₹'+' '+(120+sum);
if(cartValue == 0) {
emptyCart(arr.splice(ind, 1));
}
// }
}
})
}
let save = sum - oldSum;
function emptyCart (arr) {
document.querySelector('.box2').innerHTML = '';
addingData(arr);
// console.log(arr);
// console.log(sum, oldSum)
}
//total
// document.querySelector('.savings').textContent = '₹'+' '+save;
// document.querySelector('.totalPrice').textContent = '₹'+' '+sum;
//total end
}