mirror of
https://github.com/FranP-code/API-and-CRUD-for-Ecommerce-with-Node.js-FRONTEND.git
synced 2025-10-12 23:52:33 +00:00
payment logic done
This commit is contained in:
10
payment/script/calculateTotal.js
Normal file
10
payment/script/calculateTotal.js
Normal 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
|
||||
8
payment/script/getOrderData.js
Normal file
8
payment/script/getOrderData.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const getOrderData = () => {
|
||||
|
||||
const data = JSON.parse(sessionStorage.getItem('order'))
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
export default getOrderData
|
||||
12
payment/script/logoLink.js
Normal file
12
payment/script/logoLink.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const logoLink = () => {
|
||||
|
||||
const logo = document.querySelector('header .logo')
|
||||
|
||||
logo.addEventListener('click', () => {
|
||||
|
||||
window.location = '../'
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
export default logoLink
|
||||
50
payment/script/putOrderInHTML.js
Normal file
50
payment/script/putOrderInHTML.js
Normal 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
18
payment/script/script.js
Normal 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)
|
||||
Reference in New Issue
Block a user