|
@@ -7,7 +7,7 @@ const cartHistoryTotal = document.getElementById('cartHistoryTotal');
|
|
|
function setHistoryTable(tableData) {
|
|
function setHistoryTable(tableData) {
|
|
|
if (!tableData || tableData.length === 0) {
|
|
if (!tableData || tableData.length === 0) {
|
|
|
console.warn("No hay datos para mostrar en el historial de compras.");
|
|
console.warn("No hay datos para mostrar en el historial de compras.");
|
|
|
- table.querySelector('tbody').innerHTML = '<tr><td colspan="3" class="text-center text-gray-500">No hay historial de compras.</td></tr>';
|
|
|
|
|
|
|
+ table.querySelector('tbody').innerHTML = '<tr class="no-data"><td colspan="3" class="text-center text-gray-500">No hay historial de compras.</td></tr>';
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
table.querySelector('tbody').innerHTML = ''; // Clear existing rows
|
|
table.querySelector('tbody').innerHTML = ''; // Clear existing rows
|
|
@@ -19,11 +19,14 @@ function setHistoryTable(tableData) {
|
|
|
|
|
|
|
|
function addHistoryRow(sale) {
|
|
function addHistoryRow(sale) {
|
|
|
const newRow = rowTemplate.content.cloneNode(true);
|
|
const newRow = rowTemplate.content.cloneNode(true);
|
|
|
|
|
+ if (table.querySelector(".no-data")) {
|
|
|
|
|
+ table.querySelector(".no-data").remove(); // Remove no-data row if it exists
|
|
|
|
|
+ }
|
|
|
newRow.querySelector('.list-element-quantity').textContent = sale.quantity;
|
|
newRow.querySelector('.list-element-quantity').textContent = sale.quantity;
|
|
|
newRow.querySelector('.list-element-name').textContent = sale.productName;
|
|
newRow.querySelector('.list-element-name').textContent = sale.productName;
|
|
|
- newRow.querySelector('.list-element-price').textContent = `$${sale.price}`;
|
|
|
|
|
|
|
+ newRow.querySelector('.list-element-price').textContent = `$${sale.price * sale.quantity}`;
|
|
|
|
|
|
|
|
- addCartHistoryTotal(sale.price);
|
|
|
|
|
|
|
+ addCartHistoryTotal(sale.price * sale.quantity);
|
|
|
|
|
|
|
|
table.querySelector('tbody').appendChild(newRow);
|
|
table.querySelector('tbody').appendChild(newRow);
|
|
|
}
|
|
}
|