-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScriptLoja.js
65 lines (57 loc) · 1.48 KB
/
ScriptLoja.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
const items = [
{
id: 0,
nome: 'Bolo',
img: 'img/bolo1.jpg',
quantidade: 0
},
{
id: 1,
nome: 'Brigadeiro',
img: 'img/brigadeiro1.jpg',
quantidade: 0
},
{
id: 2,
nome: 'Torta',
img: 'img/torta.jpg',
quantidade: 0
}
]
inicializarLoja = () => {
var containerProdutos = document.getElementById('produtos');
items.map((val)=>{
containerProdutos.innerHTML+= `
<div class="produto-single">
<img src="`+val.img+`" />
<p>`+val.nome+`</p>
<a key="`+val.id+`" href="#">Adicionar ao carrinho<a/>
</div>
`;
})
}
inicializarLoja();
atualizarCarrinho = () => {
var containerCarrinho = document.getElementById('carrinho');
containerCarrinho.innerHTML = "";
items.map((val)=>{
if(val.quantidade > 0){
containerCarrinho.innerHTML+= `
<div class="info-single-checkout">
<p id="prodID" style="float:left;">Produto: `+val.nome+`</p>
<p style="float:right;">Quantidade: `+val.quantidade+`</p>
<div style="clear:both"></div>
</div>
`;
}
})
}
var links = document.getElementsByTagName('a');
for(var i = 0; i < links.length; i++){
links[i].addEventListener("click",function(){
let key = this.getAttribute('key');
items[key].quantidade++;
atualizarCarrinho();
return false;
})
}