payment logic done

This commit is contained in:
2021-11-18 22:32:55 -03:00
parent 0ff5b5b92a
commit 4bbffe9d0c
10 changed files with 165 additions and 3 deletions

View File

@@ -0,0 +1,10 @@
const calculateTotal = (totalPrice) => {
const totalElement = document.querySelector(".column.second-column h3 span")
console.log(totalElement)
totalElement.innerText = totalPrice
}
export default calculateTotal

View File

@@ -0,0 +1,8 @@
const getOrderData = () => {
const data = JSON.parse(sessionStorage.getItem('order'))
return data
}
export default getOrderData

View File

@@ -0,0 +1,12 @@
const logoLink = () => {
const logo = document.querySelector('header .logo')
logo.addEventListener('click', () => {
window.location = '../'
})
}
export default logoLink

View File

@@ -0,0 +1,50 @@
const putOrderInHTML = (order) => {
let totalPrice = 0
const table = document.querySelector('.column.second-column table tbody')
const documentFragment = document.createDocumentFragment()
for (const element in order) {
const product = order[element]
const tr = document.createElement('tr')
const orderData = {
name: element,
quantity: product.quantity,
price: product.precioAcumulado,
}
for (const key in orderData) {
const element = orderData[key];
const td = document.createElement('td')
td.innerText = element
if (key === 'name') {
td.classList.add('name')
}
if (key === 'price') {
totalPrice = totalPrice + element
}
tr.appendChild(td)
}
documentFragment.appendChild(tr)
}
table.appendChild(documentFragment)
return totalPrice
}
export default putOrderInHTML

18
payment/script/script.js Normal file
View File

@@ -0,0 +1,18 @@
import logoLink from './logoLink.js'
logoLink()
import getOrderData from './getOrderData.js'
const order = getOrderData()
if (order === null || order === {}) {
window.location = '../'
}
console.log(order)
import putOrderInHTML from './putOrderInHTML.js'
const totalPrice = putOrderInHTML(order)
import calculateTotal from './calculateTotal.js'
calculateTotal(totalPrice)