diff --git a/checkouttest.php b/checkouttest.php index 6584c87..39c262a 100644 --- a/checkouttest.php +++ b/checkouttest.php @@ -83,6 +83,8 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] + + @@ -105,6 +107,13 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] }); } + + @@ -252,19 +261,29 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] -
+ $customer) { ?> $address) { ?> -
+ +
-
@@ -278,6 +297,50 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] - Place Order + '; + } else { + // $cartItems is not empty, display the "Place Order" button + echo ' + + Place Order + '; + } + ?> + +
@@ -1016,24 +1414,59 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] for (let i = 0; i < 8; i++) { const randomIndex = Math.floor(Math.random() * refchar.length); uniqueRef += refchar.charAt(randomIndex); + // added marhc 7 2024 } + + const selectedFName = document.getElementById('selectedFName').innerText; + const selectedLName = document.getElementById('selectedLName').innerText; + const selectedContact = document.getElementById('selectedContact').innerText; + const sBuilding = document.getElementById('sBuilding').innerText; + const sStreet = document.getElementById('sStreet').innerText; + const sCity = document.getElementById('sCity').innerText; + const sBarangay = document.getElementById('sBarangay').innerText; + const sProvince = document.getElementById('sProvince').innerText; + const sCountry = document.getElementById('sCountry').innerText; + if ( + selectedFName.trim() === "" || + selectedLName.trim() === "" || + selectedContact.trim() === "" || + sBuilding.trim() === "" || + sStreet.trim() === "" || + sCity.trim() === "" || + sBarangay.trim() === "" || + sProvince.trim() === "" || + sCountry.trim() === "" + ) { + alert("Please select address."); + return; // Stop further execution + } newArray.forEach(async (orderId) => { console.log(orderId) const token = ''; const shippingfee = parseFloat(orderId.shipping_fee) + + const orderProductId = orderId.items[0].product.product_id; + const productResponse = await fetch(`https:///api/v1/products/${orderProductId}`); + const productData = await productResponse.json(); + let freeShippingCod = false; + if (productData.promo && productData.promo.length > 0 && productData.promo[0]['free-shipping'] === 'Yes') { + freeShippingCod = true; + } + + const shippingFees = freeShippingCod ? 0 : shippingfee; const patchResponse = await fetch(`https:///api/v1/orders/${orderId._id}`, { method: "PATCH", body: JSON.stringify({ shipping_address: { - shipping_first_name: document.getElementById('selectedFName').innerText, - shipping_last_name: document.getElementById('selectedLName').innerText, - shipping_phone: document.getElementById('selectedContact').innerText, - shipping_address_1: document.getElementById('sBuilding').innerText, - shipping_address_2: document.getElementById('sStreet').innerText, - shipping_city: document.getElementById('sCity').innerText, - shipping_barangay: document.getElementById('sBarangay').innerText, - shipping_state: document.getElementById('sProvince').innerText, - shipping_country: document.getElementById('sCountry').innerText, + shipping_first_name: selectedFName, + shipping_last_name: selectedLName, + shipping_phone: selectedContact, + shipping_address_1: sBuilding, + shipping_address_2: sStreet, + shipping_city: sCity, + shipping_barangay: sBarangay, + shipping_state: sProvince, + shipping_country: sCountry, }, billing_address: { billing_first_name: billingFName, @@ -1050,7 +1483,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] status: "UNPAID", reference_number: uniqueRef, }, - total_amount: parseFloat(orderId.total_amount) + shippingfee, + total_amount: parseFloat(orderId.total_amount) + shippingFees, status: "TO PAY", order_date: iso8601String, payment_method: "Cash On Delivery", @@ -1060,7 +1493,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] 'Authorization': "Bearer " + token, }, }); - + // added marhc 7 2024 if (!patchResponse.ok) { throw new Error(`Error updating payment status: ${patchResponse.status} ${patchResponse.statusText}`); } diff --git a/vendor-all-product-list.php b/vendor-all-product-list.php index 1b60653..9519ddb 100644 --- a/vendor-all-product-list.php +++ b/vendor-all-product-list.php @@ -64,6 +64,8 @@ $products = productList(); + + @@ -138,9 +140,12 @@ $products = productList();
Product List
-
+
- Add + + Delete Selected + + Add
@@ -166,8 +171,10 @@ $products = productList(); for ($i = 0; $i <= $totalProducts - 1; $i++) { $product = $products[$i]; ?> - + + + - - - + + + + + + - + @@ -223,6 +233,7 @@ $products = productList(); var email = ''; var password = ''; + function deleteProduct(productId) { let text = "Please confirm delete action!\nClick OK or Cancel button."; if (confirm(text) == true) { @@ -295,13 +306,54 @@ $products = productList(); // function editProduct(productId) { // window.open("vendor-uploads.php?id=" + productId, "_self"); // } - function addProduct() { + function addProduct(productId) { console.log("Session Token:", sessionToken); login(email, password, function() { // Removed the call to updateSessionToken - window.open("vendor-uploads-add-product-action.php", "_self"); + window.open("vendor-uploads-add-product-action.php" + productId, "_self"); }); } + + // multiple delete when checking the checkbox + function deleteSelectedProduct() { + var checkboxes = document.querySelectorAll('input[name="product_checkbox[]"]:checked'); + if (checkboxes.length === 0) { + alert('Please select at least one product to delete.'); + return; + } + var selectedProductIds = []; + checkboxes.forEach(function (checkbox) { + selectedProductIds.push(checkbox.value); + }); + var text = "Please confirm delete action!\nClick OK or Cancel button."; + if (confirm(text) == true) { + selectedProductIds.forEach(function(productId) { + fetch("https:///api/v1/products/" + productId, { + method: "DELETE" + }) + .then(response => { + if (response.ok) { + console.log("Product with ID " + productId + " deleted successfully."); + // Remove the deleted product row from the table + var productRow = document.getElementById(productId); + if (productRow) { + productRow.remove(); + } else { + console.error("Product row with ID " + productId + " not found in the DOM."); + } + } else { + throw new Error("Error deleting product with ID " + productId + ": " + response.statusText); + } + }) + .catch(error => { + console.error(error.message); + }); + }); + } + } + + +