From 2f599791df417047733b16b9836b9728f4bf45f4 Mon Sep 17 00:00:00 2001 From: Jun Barroga Date: Mon, 22 Apr 2024 09:50:50 +0800 Subject: [PATCH 1/2] Fix Bugs on Checkout --- checkouttest.php | 48 +++++++++++++++++++++++++++++++------ functions.php | 29 ++++++++++++++++++++++ user-history.php | 10 ++++---- vendor-all-product-list.php | 2 +- vendor-payments.php | 1 + vendor-settings.php | 26 ++++++++++---------- 6 files changed, 90 insertions(+), 26 deletions(-) diff --git a/checkouttest.php b/checkouttest.php index 2255fb1..4cfb43c 100644 --- a/checkouttest.php +++ b/checkouttest.php @@ -1249,6 +1249,29 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] let itemNames = []; submitButton.addEventListener('click', async function() { if (pay1RadioButton.checked) { + 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; + } try { @@ -1348,15 +1371,24 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] const newArray = Object.values(ordersToUpdate) console.log(newArray) const refchar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - let uniqueRef = ''; - for (let i = 0; i < 8; i++) { - const randomIndex = Math.floor(Math.random() * refchar.length); - uniqueRef += refchar.charAt(randomIndex); - } + // let uniqueRef = ''; + // for (let i = 0; i < 8; i++) { + // const randomIndex = Math.floor(Math.random() * refchar.length); + // uniqueRef += refchar.charAt(randomIndex); + // } newArray.forEach(async (orderId) => { console.log(orderId) const token = ''; const shippingfee = parseFloat(orderId.shipping_fee) + const orderPay3ProductId = orderId.items[0].product.product_id; + const productPay3Response = await fetch(`https:///api/v1/products/${orderProductId}`); + const productPay3Data = await productPay3Response.json(); + let freeShippingObPay = false; + if (productPay3Data.promo && productPay3Data.promo.length > 0 && productPay3Data.promo[0]['free-shipping'] === 'Yes') { + freeShippingObPay = true; + } + const shippingFeesPay3 = freeShippingObPay ? 0 : shippingfee; + const patchResponse = await fetch(`https:///api/v1/orders/${orderId._id}`, { method: "PATCH", body: JSON.stringify({ @@ -1386,7 +1418,8 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] status: "UNPAID", reference_number: result.attributes.reference_number, }, - total_amount: parseFloat(orderId.total_amount) + shippingfee, + shipping_fee: shippingFeesPay3, + total_amount: parseFloat(orderId.total_amount) + shippingFeesPay3, order_date: iso8601String, payment_method: "Obananapay", }), @@ -1492,6 +1525,7 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] }, total_amount: parseFloat(orderId.total_amount) + shippingFees, status: "TO PAY", + shipping_fee: shippingFees, order_date: iso8601String, payment_method: "Cash On Delivery", }), @@ -2171,4 +2205,4 @@ if (isset($customer_data[0]["address"]) && is_array($customer_data[0]["address"] - \ No newline at end of file + diff --git a/functions.php b/functions.php index 7959cd1..d8bd171 100644 --- a/functions.php +++ b/functions.php @@ -274,6 +274,35 @@ function productListVendor($vendorId) return $json; // Add this line to return the decoded JSON data } +function allProductListVendor($vendorId) +{ + $curl = curl_init(); + $url = "https://" . $_SESSION["data_endpoint"] . "/api/v1/products/vendor/" . $vendorId; + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt_array($curl, array( + //CURLOPT_URL => 'https://".$_SESSION["data_endpoint"]."/api/v1/products/vendor/6527b593f79b5deac5ad6cb8', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'X-Api-Key: {{apiKey}}' + ), + )); + $response = curl_exec($curl); + curl_close($curl); + $json = json_decode($response, true); + $products = array_filter($json, function ($var) { + return ($var['product_type'] == '' || $var['product_type'] == 'simple' || $var['product_type'] == 'variable' || $var['product_type'] == 'variation'); + }); + $products = array_values($products); + return $products; + return $json; // Add this line to return the decoded JSON data +} + function getProductVariations($parent_id) { $curl = curl_init(); diff --git a/user-history.php b/user-history.php index 9dd041e..b9becb2 100644 --- a/user-history.php +++ b/user-history.php @@ -353,9 +353,7 @@ if ($_SESSION["isVendor"] == true) { $_SESSION['cart_items'] = $order_data; foreach ($order_data as $order) { // Ensure that the required data is available before accessing it - if (isset($order['status']) && (strtoupper($order['status']) === 'TO PAY') || (strtoupper($order['status']) === 'TO SHIP') - || (strtoupper($order['status']) === 'TO RECEIVE') || (strtoupper($order['status']) === 'COMPLETED') - && isset($order['items'][0]['product'])) { + if (isset($order['status']) && (strtoupper($order['status']) === 'TO PAY' || strtoupper($order['status']) === 'TO SHIP' || strtoupper($order['status']) === 'TO RECEIVE' || strtoupper($order['status']) === 'COMPLETED') && isset($order['items'][0]['product'])) { $orderExist = true; $totalAmount += $order['total_amount']; ?> @@ -376,9 +374,9 @@ if ($_SESSION["isVendor"] == true) {

No Purchased Order/s Yet.

'; - } + // if (empty($order['status'])) { + // echo '

No Purchased Order/s Yet.

'; + // } } } // } else if (empty($order['status'])) { diff --git a/vendor-all-product-list.php b/vendor-all-product-list.php index fe9defd..7645feb 100644 --- a/vendor-all-product-list.php +++ b/vendor-all-product-list.php @@ -202,7 +202,7 @@ $products = productList(); -
+
>