-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkout.js
61 lines (50 loc) · 2.15 KB
/
checkout.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
console.log('Hit!!')
const searchParams = new URLSearchParams(window.location.search)
const id = searchParams.get('id')
const cart_url = "http://localhost:3000/carts"
const cartid_url = `http://localhost:3000/carts/${id}`
// const div= document.querySelector('div')
fetch(cart_url)
.then(res => res.json())
.then(carts =>{
console.log(carts)
carts.map(cart =>{
cart.coffees.map(coffee =>{
let div = document.createElement('div')
let quantitycontainer = document.createElement('quantitycontainer')
let coffeeName = document.createElement('h5')
let coffeeImg = new Image (200,200)
let coffeePrice = document.createElement('h5')
let coffeeQuantity = document.createElement ('input')
const button = document.createElement("button")
div.className = 'coffeeNameContainer'
quantityinput = 'quantitybox'
coffeeName.className = 'coffeeName'
coffeePrice.className = 'coffeePrice'
coffeeImg.className = 'coffeeImg'
button.className = 'button'
coffeeQuantity.className = 'coffeequantity'
coffeeName.innerText = `${coffee.coffee_roaster.name}${coffee.blend.name}`
coffeeImg.src = coffee.image
coffeePrice.innerText = coffee.price
coffeeQuantity.type = "number"
button.innerText = "remove";
quantitycontainer.appendChild(coffeeQuantity)
div.append(coffeeImg, coffeeName, coffeePrice,quantitycontainer, button)
document.body.appendChild(div)
// console.log(coffee.cart_id)
// console.log(coffee.id)
button.addEventListener ("click", function(){
console.log(confirm("remove"))
fetch(`http://localhost:3000/delete_cart_item/?cart_id=${coffee.cart_id}&coffee_id=${coffee.id}`,{
method: "PATCH",
headers:{
"Content-Type": "application/json"
},
body: JSON.stringify({
})
})
})
})
})
})