From c530e8c7d7fa8bee54d2c7b5937ab634cc0ef6aa Mon Sep 17 00:00:00 2001 From: Jun Barroga Date: Fri, 5 Apr 2024 11:08:15 +0800 Subject: [PATCH] Modified the Application of Price Matrix When Updating Order --- product-left-sidebar.php | 70 +++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/product-left-sidebar.php b/product-left-sidebar.php index ca03584..9c6821e 100644 --- a/product-left-sidebar.php +++ b/product-left-sidebar.php @@ -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:///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:///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)); }