Fix Bugs on Checkout
This commit is contained in:
parent
b978919ccb
commit
2f599791df
|
@ -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 {
|
||||
<?php foreach ($cartItems as $checkout) { ?>
|
||||
<?php foreach ($checkout['items'] as $item) { ?>
|
||||
|
@ -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 = '<?php echo $_SESSION["token"] ?>';
|
||||
const shippingfee = parseFloat(orderId.shipping_fee)
|
||||
const orderPay3ProductId = orderId.items[0].product.product_id;
|
||||
const productPay3Response = await fetch(`https://<?php echo $_SESSION["data_endpoint"]; ?>/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://<?php echo $_SESSION["data_endpoint"]; ?>/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"]
|
|||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
|||
<?php
|
||||
}
|
||||
}
|
||||
if (empty($order['status'])) {
|
||||
echo '<tr><p style="padding-top:30px; padding-left:20px;">No Purchased Order/s Yet.</p></tr>';
|
||||
}
|
||||
// if (empty($order['status'])) {
|
||||
// echo '<tr><p style="padding-top:30px; padding-left:20px;">No Purchased Order/s Yet.</p></tr>';
|
||||
// }
|
||||
}
|
||||
}
|
||||
// } else if (empty($order['status'])) {
|
||||
|
|
|
@ -202,7 +202,7 @@ $products = productList();
|
|||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$products = productListVendor($vendorId);
|
||||
$products = allProductListVendor($vendorId);
|
||||
$totalProducts = count($products);
|
||||
// 03-11-2024 Stacy added for products pagination
|
||||
$productsPerPage = 10;
|
||||
|
|
|
@ -485,6 +485,7 @@ if ($_SESSION["isCustomer"] == true) {
|
|||
},
|
||||
success: function(response) {
|
||||
// Handle successful response
|
||||
console.log(response);
|
||||
var paymentId = response.payment.reference_number;
|
||||
$('#paymentIdSpan').text(paymentId);
|
||||
var gross_price = response.payment.details[0]?.attributes.data.attributes.amount;
|
||||
|
|
|
@ -322,7 +322,7 @@ if ($_SESSION["isCustomer"] == true) {
|
|||
</label>
|
||||
</div>
|
||||
|
||||
<div class="selectWrap" style="display: flex; justify-content: center; align-items: center; width: 50%; margin-left:-20px;">
|
||||
<div class="selectWrap" style="display: flex; justify-content: center; align-items: center; width: 50%;">
|
||||
<input type="radio" style="padding-left: 0px !important; margin: 0px 0px !important;" name="selectedShippingAddress[<?php echo $vendor_index; ?>]" id="shipping_address_<?php echo $vendor_index; ?>_<?php echo $address_index; ?>" value="<?php echo $vendor_index; ?>_<?php echo $address_index; ?>" class="form-check-input" onchange="updateAddressShipping('<?php echo $vendor['_id']; ?>', <?php echo $address_index; ?>, true)" <?php echo $address["shipping"] ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" style="margin: 0px 10px !important;" for="shipping_address_<?php echo $vendor_index; ?>_<?php echo $address_index; ?>">
|
||||
Shipping Address
|
||||
|
@ -530,17 +530,19 @@ if ($_SESSION["isCustomer"] == true) {
|
|||
<div class="card-body">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12 mx-auto">
|
||||
<label class="form-check-label" for="address_<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>">
|
||||
<strong style="font-weight: bold;">Bank Name: </strong><?php echo $bank['bank_name']; ?> <br>
|
||||
<strong style="font-weight: bold;">Bank Account Number: </strong><?php echo $bank['bank_account_number']; ?> <br>
|
||||
<strong style="font-weight: bold;">Bank Account Name: </strong><?php echo $bank['bank_account_name']; ?>
|
||||
<div class="selectWrap" style="display: flex; justify-content: center; align-items: center; width: 50%;">
|
||||
<input type="radio" name="payout_bank" id="payout_bank_<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>" value="<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>" onchange="setPayoutBank('<?php echo $vendor['_id']; ?>', <?php echo $bank_index; ?>, true)" <?php echo $bank['bank_payout'] ? 'checked' : ''; ?>>
|
||||
<label for="payout_bank_<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>">Set as Payout Bank</label>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-md-12 mx-auto">
|
||||
<div class="form-check" style="display: flex; align-items: center;">
|
||||
<label class="form-check-label" for="address_<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>">
|
||||
<strong style="font-weight: bold;">Bank Name: </strong><?php echo $bank['bank_name']; ?> <br>
|
||||
<strong style="font-weight: bold;">Bank Account Number: </strong><?php echo $bank['bank_account_number']; ?> <br>
|
||||
<strong style="font-weight: bold;">Bank Account Name: </strong><?php echo $bank['bank_account_name']; ?>
|
||||
</label>
|
||||
<div class="selectWrap" style="margin-left: auto; display: flex; align-items: center;">
|
||||
<input type="radio" style="height:15px !important; width: 15px !important;" name="payout_bank" id="payout_bank_<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>" value="<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>" onchange="setPayoutBank('<?php echo $vendor['_id']; ?>', <?php echo $bank_index; ?>, true)" <?php echo $bank['bank_payout'] ? 'checked' : ''; ?>>
|
||||
<label for="payout_bank_<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>" style="margin-bottom: 0; margin-left: 5px;">Set as Payout Bank</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue