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:
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
|
||||
Reference in New Issue
Block a user