jun-branch #55

Merged
MarkHipe merged 4 commits from jun-branch into main 2024-04-16 10:07:53 +08:00
1 changed files with 34 additions and 36 deletions
Showing only changes of commit c530e8c7d7 - Show all commits

View File

@ -1004,49 +1004,47 @@ if (isset($_GET['id'])) {
var updatedQuantity = existingQuantity + newQuantity;
// Check if the updated quantity exceeds the previous price matrix
var newProductPrice = productPrice; // Assume the initial productPrice
var foundNewPrice = false;
if (priceMatrix.length > 0) {
for (var i = 0; i < priceMatrix.length; i++) {
for (var j = 0; j < priceMatrix[i].length; j++) {
if (updatedQuantity <= parseInt(priceMatrix[i][j].quantity)) {
newProductPrice = parseFloat(priceMatrix[i][j].price);
foundNewPrice = true;
break;
}
}
if (foundNewPrice) {
break;
}
}
var newProductPrice = productPrice;
var foundNewPrice = false;
if (priceMatrix.length > 0) {
for (var i = 0; i < priceMatrix.length; i++) {
for (var j = 0; j < priceMatrix[i].length; j++) {
if (updatedQuantity <= parseInt(priceMatrix[i][j].quantity)) {
newProductPrice = parseFloat(priceMatrix[i][j].price);
foundNewPrice = true;
break;
}
}
if (foundNewPrice) {
break;
}
}
}
// Update product price if a new price is found in the price matrix
if (foundNewPrice) {
productPrice = newProductPrice;
}
// Update product price if a new price is found in the price matrix
if (foundNewPrice) {
productPrice = newProductPrice;
}
var updateData = {
quantity: updatedQuantity,
price: productPrice // Update the price for the item
};
var updateData = {
quantity: updatedQuantity,
price: productPrice // Update the price for the item
};
updateOrderXhr.send(JSON.stringify(updateData));
updateOrderXhr.send(JSON.stringify(updateData));
var patchTotalAmountXhr = new XMLHttpRequest();
patchTotalAmountXhr.open("PATCH", `https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/orders/${orderId}`, true);
patchTotalAmountXhr.setRequestHeader("Content-Type", "application/json");
patchTotalAmountXhr.setRequestHeader("Authorization", "Bearer " + token);
// Patch the total amount of the order with the updated price and quantity
var patchTotalAmountXhr = new XMLHttpRequest();
patchTotalAmountXhr.open("PATCH", `https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/orders/${orderId}`, true);
patchTotalAmountXhr.setRequestHeader("Content-Type", "application/json");
patchTotalAmountXhr.setRequestHeader("Authorization", "Bearer " + token);
var originalPrice = document.getElementById("productPrice").innerText;
var totalAmount = originalPrice * updatedQuantity;
console.log(originalPrice);
console.log(totalAmount);
var patchData = {
total_amount: totalAmount
};
var totalAmount = productPrice * updatedQuantity;
var patchData = {
total_amount: totalAmount
};
patchTotalAmountXhr.send(JSON.stringify(patchData));
patchTotalAmountXhr.send(JSON.stringify(patchData));
}