forked from VaishnaviR99/PharmEasy_clone13
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct.js
More file actions
39 lines (28 loc) · 816 Bytes
/
product.js
File metadata and controls
39 lines (28 loc) · 816 Bytes
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
// image Name manuf qty strikedoff price discount
var productIncart = JSON.parse(localStorage.getItem("cart"))||[];
document.getElementById("addincart").addEventListener("click", function(){
addtoCart(productIncart);
});
var rs = -1;
function addtoCart(elem) {
alert("Item Added to Cart");
location.reload();
var check = false;
var idxc = -1;
productIncart.map(function (ele, idx) {
if (ele.name == elem.name) {
check = true;
idxc = idx;
}
});
rs = Number(elem.qty);
if (check) {
elem.qty = Number(elem.qty) + Number(1);
productIncart.splice(idxc, 1);
} else {
elem.qty = 1;
}
productIncart.push(elem);
localStorage.setItem("cart", JSON.stringify(productIncart));
location.reload();
}