Apply Price Matrix, Admin Payout Token Renew, Admin Login Redirections
This commit is contained in:
parent
da6b386ba6
commit
d056602c30
|
@ -81,7 +81,7 @@ if ($_SESSION["isLoggedIn"] == true and $_SESSION["user_type"] == "admin"){
|
|||
<?php
|
||||
}
|
||||
?>
|
||||
<form action="../login_action.php" method="post">
|
||||
<form action="login_action_admin.php" method="post">
|
||||
<div class="mb-3 mt-3">
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" class="form-control" id="email" placeholder="Enter email" name="name">
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
include "../functions.php";
|
||||
|
||||
$url = $_SESSION["url"];
|
||||
$_SESSION["email"] = $_POST["name"];
|
||||
$_SESSION["password"] = $_POST["password"];
|
||||
$result = login($_SESSION["email"],$_SESSION["password"]);
|
||||
|
||||
if ($result) {
|
||||
$_SESSION["token"] = $result;
|
||||
$result = profile($_SESSION["token"]);
|
||||
$_SESSION["userId"] = $result["profile"]["userId"];
|
||||
$_SESSION["user_type"] = $result["user_type"];
|
||||
$result = customerExists($_SESSION["email"]);
|
||||
if ($result > 0) {
|
||||
$_SESSION["isCustomer"] = true;
|
||||
}
|
||||
$result = vendorExists($_SESSION["email"]);
|
||||
if ($result > 0) {
|
||||
$_SESSION["isVendor"] = true;
|
||||
}
|
||||
header("location: index.php");
|
||||
} else {
|
||||
// $_SESSION["loginError"] = "Invalid email or password. Please try again.";
|
||||
header("location: login.php?error=1");
|
||||
}
|
||||
|
||||
|
||||
// $_SESSION["token"] = $result;
|
||||
// $result = profile($_SESSION["token"]);
|
||||
// $_SESSION["userId"] = $result["profile"]["userId"];
|
||||
// $result = customerExists($_SESSION["email"]);
|
||||
// if($result>0){
|
||||
// $_SESSION["isCustomer"] = true;
|
||||
// }
|
||||
// $result = vendorExists($_SESSION["email"]);
|
||||
// if($result>0){
|
||||
// $_SESSION["isVendor"] = true;
|
||||
// }
|
||||
// header("location: $url")
|
||||
?>
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
include "../functions.php";
|
||||
|
||||
$token = loginRenew($_SESSION["email"], $_SESSION["password"], $_SESSION["token"]);
|
||||
$_SESSION["token"] = $token;
|
||||
|
||||
header("Location: vendor-profile.php");
|
||||
exit;
|
||||
|
||||
?>
|
|
@ -65,21 +65,20 @@ foreach ($vendorPayouts as $payout) {
|
|||
}
|
||||
}
|
||||
|
||||
$token = $_SESSION["token"];
|
||||
if (isset($_SESSION["token"])) {
|
||||
$token = $_SESSION["token"];
|
||||
$token_parts = explode(".", $token);
|
||||
$token_payload = base64_decode($token_parts[1]);
|
||||
$token_data = json_decode($token_payload);
|
||||
|
||||
$token_parts = explode(".", $token);
|
||||
$token_payload = base64_decode($token_parts[1]);
|
||||
$token_data = json_decode($token_payload);
|
||||
$issued_at_time = $token_data->iat;
|
||||
$expiration_time = $token_data->exp;
|
||||
$renewal_time = $issued_at_time + 3300;
|
||||
|
||||
$expiration_time = $token_data->exp;
|
||||
$issued_at_time = $token_data->iat;
|
||||
|
||||
$renewal_time = $issued_at_time + 3300;
|
||||
|
||||
|
||||
if (time() >= $renewal_time) {
|
||||
$token = loginRenew($_SESSION["email"], $_SESSION["password"], $token);
|
||||
$_SESSION["token"] = $token;
|
||||
if (time() >= $renewal_time || time() >= $expiration_time) {
|
||||
header("Location: token-renew.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// $token = loginRenew($_SESSION["email"], $_SESSION["password"], $token);
|
||||
// $_SESSION["token"] = $token;
|
||||
|
@ -115,6 +114,23 @@ if (time() >= $renewal_time) {
|
|||
<!-- FAVICON -->
|
||||
<link href="assets/img/favicon.png" rel="shortcut icon" />
|
||||
|
||||
<script>
|
||||
function renewToken() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "token-renew.php", true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
setInterval(function() {
|
||||
var currentTime = <?php echo time(); ?>;
|
||||
var renewalTime = <?php echo $renewal_time; ?>;
|
||||
var expirationTime = <?php echo $expiration_time; ?>;
|
||||
|
||||
if (currentTime >= renewalTime || currentTime >= expirationTime) {
|
||||
renewToken();
|
||||
}
|
||||
}, 60000);
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body class="ec-header-fixed ec-sidebar-fixed ec-sidebar-dark ec-header-light" id="body">
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
if ($result > 0) {
|
||||
$_SESSION["isVendor"] = true;
|
||||
}
|
||||
header("location: $url");
|
||||
header("location: index.php");
|
||||
} else {
|
||||
// $_SESSION["loginError"] = "Invalid email or password. Please try again.";
|
||||
header("location: login.php?error=1");
|
||||
|
|
|
@ -215,7 +215,8 @@ if (isset($_GET['id'])) {
|
|||
right: 15px;
|
||||
bottom: 0;
|
||||
border-radius: 0 0 10px 10px;
|
||||
}
|
||||
}
|
||||
|
||||
/* 02-21-2024 Stacy added css for addtocart & wishlist */
|
||||
</style>
|
||||
</head>
|
||||
|
@ -276,17 +277,17 @@ if (isset($_GET['id'])) {
|
|||
<div class="single-pro-inner">
|
||||
<!-- 02-20-2024 Stacy message sent pop-up -->
|
||||
<?php
|
||||
if (isset($_SESSION["SuccessfullySent"])) {
|
||||
echo '<div class="alert alert-success" id="alertSuccess" role="alert"; content-align:center;>';
|
||||
echo $_SESSION["SuccessfullySent"];
|
||||
echo '</div>';
|
||||
unset($_SESSION["SuccessfullySent"]);
|
||||
echo " <script>
|
||||
if (isset($_SESSION["SuccessfullySent"])) {
|
||||
echo '<div class="alert alert-success" id="alertSuccess" role="alert"; content-align:center;>';
|
||||
echo $_SESSION["SuccessfullySent"];
|
||||
echo '</div>';
|
||||
unset($_SESSION["SuccessfullySent"]);
|
||||
echo " <script>
|
||||
setTimeout(function() {
|
||||
document.getElementById('alertSuccess').style.display = 'none';
|
||||
}, 10000);
|
||||
</script>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!-- 02-20-2024 Stacy message sent pop-up -->
|
||||
<div class="row">
|
||||
|
@ -325,7 +326,8 @@ if (isset($_GET['id'])) {
|
|||
$productImage = $i;
|
||||
}
|
||||
?>
|
||||
<!-- <img class="img-responsive" src="<?php #echo $productImage; ?>" alt="" style="width: 100%; height: 100%; object-fit: cover; object-position: center center;"> -->
|
||||
<!-- <img class="img-responsive" src="<?php #echo $productImage;
|
||||
?>" alt="" style="width: 100%; height: 100%; object-fit: cover; object-position: center center;"> -->
|
||||
<!-- 02-26-2024 Stacy updated img width & height -->
|
||||
<img class="img-responsive" src="<?php echo $productImage; ?>" alt="" style="max/width: 90px; height: 120px; object-fit: cover; object-position: center center;">
|
||||
</div>
|
||||
|
@ -378,16 +380,16 @@ if (isset($_GET['id'])) {
|
|||
<div class="ec-single-price">
|
||||
<span class="ec-single-ps-title">As low as</span>
|
||||
<?php
|
||||
// 02-13-24 Jun Jihad Removed Logic to DIsplay Price Range of Variable Products
|
||||
if (isset($product_details['sale_price']) && $product_details['sale_price'] > 0) {
|
||||
echo '<s><span id="productPrice" class="old-price">' . $product_details['regular_price'] . '</span></s>';
|
||||
echo '<span id="productNewPrice" class="new-price">' . $product_details['sale_price'] . '</span>';
|
||||
} elseif (!isset($product_details['regular_price']) || $product_details['regular_price'] <= 0) {
|
||||
echo '<span id="productPrice" class="new-price">Contact Seller for Price</span>';
|
||||
} else {
|
||||
echo '<span id="productPrice" class="new-price">' . $product_details['regular_price'] . '</span>';
|
||||
}
|
||||
// 02-13-24 Jun Jihad Removed Logic to DIsplay Price Range of Variable Products
|
||||
// 02-13-24 Jun Jihad Removed Logic to DIsplay Price Range of Variable Products
|
||||
if (isset($product_details['sale_price']) && $product_details['sale_price'] > 0) {
|
||||
echo '<s><span id="productPrice" class="old-price">' . $product_details['regular_price'] . '</span></s>';
|
||||
echo '<span id="productNewPrice" class="new-price">' . $product_details['sale_price'] . '</span>';
|
||||
} elseif (!isset($product_details['regular_price']) || $product_details['regular_price'] <= 0) {
|
||||
echo '<span id="productPrice" class="new-price">Contact Seller for Price</span>';
|
||||
} else {
|
||||
echo '<span id="productPrice" class="new-price">' . $product_details['regular_price'] . '</span>';
|
||||
}
|
||||
// 02-13-24 Jun Jihad Removed Logic to DIsplay Price Range of Variable Products
|
||||
?>
|
||||
</div>
|
||||
<div class="ec-single-stoke">
|
||||
|
@ -396,7 +398,7 @@ if (isset($_GET['id'])) {
|
|||
|
||||
</div>
|
||||
</div>
|
||||
<!-- 20240212 Jun Jihad Include Parent Product in the Variation Selection -->
|
||||
<!-- 20240212 Jun Jihad Include Parent Product in the Variation Selection -->
|
||||
<?php
|
||||
if (isset($variation_details) && is_array($variation_details)) {
|
||||
?>
|
||||
|
@ -405,7 +407,7 @@ if (isset($_GET['id'])) {
|
|||
<span>VARIATION</span>
|
||||
<div class="ec-pro-variation-content">
|
||||
<ul class="eccart-pro-items">
|
||||
<?php
|
||||
<?php
|
||||
$main_product_image = isset($product_details["product_image"]) ? $product_details["product_image"] : 'https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg';
|
||||
?>
|
||||
<a href="javascript:void(0);" onclick="selectVariation(<?php echo htmlspecialchars(json_encode($product_details), ENT_QUOTES, 'UTF-8'); ?>)">
|
||||
|
@ -478,29 +480,30 @@ if (isset($_GET['id'])) {
|
|||
|
||||
<div class="qty-plus-minuses" style="display:flex; overflow:visible;">
|
||||
<!-- <div class="qty-btn" style="color:#ffaa00; font-size:35px; padding-right:5px; cursor: pointer;" onclick="decrement()">-</div>
|
||||
<input class="qty-inputs" style="width:100px; height:40px" type="number" name="ec_qtybtn" value="<?php #echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1"; ?>" id="qty-input" />
|
||||
<input class="qty-inputs" style="width:100px; height:40px" type="number" name="ec_qtybtn" value="<?php #echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1";
|
||||
?>" id="qty-input" />
|
||||
<div class="qty-btn" style="color:#ffaa00; font-size:25px; padding-left:5px; cursor: pointer;" onclick="increment()">+</div> -->
|
||||
|
||||
|
||||
<div class="ec-single-cart" style="display:flex; flex-direction:row; width:80%; overflow:visible; text-align:center; align-items:center; ">
|
||||
<!-- 02-13-24 Jun Jihad Contact Seller will appear to Variable products with no price -->
|
||||
<?php
|
||||
<!-- 02-13-24 Jun Jihad Contact Seller will appear to Variable products with no price -->
|
||||
<?php
|
||||
if ($_SESSION["isLoggedIn"]) {
|
||||
if ($product_details['product_type'] === "variable") {
|
||||
echo '<div class="qty-btn" style="color:#ffaa00; font-size:35px; padding-right:5px; cursor: pointer;" onclick="decrement()">-</div>';
|
||||
echo '<input class="qty-inputs" style="width:110px; height:40px" type="number" name="ec_qtybtn" value="';
|
||||
echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1";
|
||||
echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1";
|
||||
echo '" id="qty-input" />';
|
||||
echo '<div class="qty-btn" style="color:#ffaa00; font-size:25px; padding-left:5px; cursor: pointer;" onclick="increment()">+</div>';
|
||||
echo '<div style="display:flex; margin-left:45px;"><button type="button" class="btn btn-primary" id="contactSellerButton" style="background:#ffaa00; width:190px;" data-bs-toggle="modal" data-bs-target="#priceModal"><i class="fi-rr-envelope" style="font-size:20px; margin-bottom:-3px; margin-right:10px;"></i>Contact Seller</button>';
|
||||
echo '<button class="btn btn-primary" id="addToCartButton" style="display:none">Add To Cart</button>';
|
||||
echo '<div class="ec-single-wishlist">
|
||||
<a class="ec-btn-group wishlist" title="Wishlist" onclick="wishlist()"><i class="fi fi-rr-heart" style="color:#B80F0A; font-size:20px;"></i></a>
|
||||
</div></div>';
|
||||
|
||||
} else {
|
||||
if (!empty($product_details['regular_price']) || !empty($product_details['sale_price'])) {
|
||||
echo '<div class="qty-btn" style="color:#ffaa00; font-size:35px; padding-right:5px; cursor: pointer;" onclick="decrement()">-</div>';
|
||||
echo '<input class="qty-inputs" style="width:100px; height:40px" type="number" name="ec_qtybtn" value="';
|
||||
echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1";
|
||||
echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1";
|
||||
echo '" id="qty-input" />';
|
||||
echo '<div class="qty-btn" style="color:#ffaa00; font-size:25px; padding-left:5px; cursor: pointer;" onclick="increment()">+</div>';
|
||||
// echo '<div id="addToCartMessage" style="border:1px solid red;"></div>';
|
||||
|
@ -516,30 +519,30 @@ if (isset($_GET['id'])) {
|
|||
echo '<div class="login-button" style=""><p style="color:red; text-wrap:nowrap;">Please log in to your account.</p>';
|
||||
echo '<a href="login.php" style="margin-left:-2px;"><button type="button" class="btn btn-primary" style="margin-left:-2px; margin-top:-20px; background:#ffaa00; border-radius:10px; letter-spacing:1px;" data-bs-toggle="modal">LOGIN</button></a></div>';
|
||||
}
|
||||
?>
|
||||
<!-- <div class="ec-single-wishlist" style="border: 1px solid yellow;">
|
||||
?>
|
||||
<!-- <div class="ec-single-wishlist" style="border: 1px solid yellow;">
|
||||
<a class="ec-btn-group wishlist" style="padding-left:40px;" title="Wishlist" onclick="wishlist()"><i class="fi fi-rr-heart"></i></a>
|
||||
</div> -->
|
||||
<!-- 02-22-2024 Stacy modified this block of code -->
|
||||
|
||||
<!-- 02-13-24 Jun Jihad Contact Seller will appear to Variable products with no price -->
|
||||
<!-- 02-22-2024 Stacy modified this block of code -->
|
||||
|
||||
<!-- 02-13-24 Jun Jihad Contact Seller will appear to Variable products with no price -->
|
||||
|
||||
|
||||
<!-- <?php
|
||||
// if ($_SESSION["isLoggedIn"]) {
|
||||
// if ($product_details['product_type'] === "variable") {
|
||||
// echo '<button class="btn btn-primary" id="addToCartButton" disabled>Add To Cart</button>';
|
||||
// echo '<button type="button" class="btn btn-primary" id="contactSellerButton" style="display:none" data-bs-toggle="modal" data-bs-target="#priceModal">Contact seller</button>';
|
||||
// } elseif ($product_details['regular_price'] && $product_details['regular_price'] !== "") {
|
||||
// echo '<div id="addToCartMessage"></div>';
|
||||
// echo '<button class="btn btn-primary" id="addToCartButton">Add To Cart</button>';
|
||||
// } else {
|
||||
// echo '<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#priceModal">Contact seller</button>';
|
||||
// }
|
||||
// } else {
|
||||
// echo '<p>Please log in to add to cart.</p>';
|
||||
// }
|
||||
?> -->
|
||||
<!-- <?php
|
||||
// if ($_SESSION["isLoggedIn"]) {
|
||||
// if ($product_details['product_type'] === "variable") {
|
||||
// echo '<button class="btn btn-primary" id="addToCartButton" disabled>Add To Cart</button>';
|
||||
// echo '<button type="button" class="btn btn-primary" id="contactSellerButton" style="display:none" data-bs-toggle="modal" data-bs-target="#priceModal">Contact seller</button>';
|
||||
// } elseif ($product_details['regular_price'] && $product_details['regular_price'] !== "") {
|
||||
// echo '<div id="addToCartMessage"></div>';
|
||||
// echo '<button class="btn btn-primary" id="addToCartButton">Add To Cart</button>';
|
||||
// } else {
|
||||
// echo '<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#priceModal">Contact seller</button>';
|
||||
// }
|
||||
// } else {
|
||||
// echo '<p>Please log in to add to cart.</p>';
|
||||
// }
|
||||
?> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -594,10 +597,10 @@ if (isset($_GET['id'])) {
|
|||
<form action="contact-seller-action.php" method="post">
|
||||
<label for="">Enter product details such as color,size,materials,etc. and other specification requirements to receive an accurate quote</label>
|
||||
<textarea name="message" id="" cols="30" rows="5"></textarea>
|
||||
<input name="product_name" type="hidden" value='<?php echo $product_details['product_name']; ?>'/>
|
||||
<input name="product_name" type="hidden" value='<?php echo $product_details['product_name']; ?>' />
|
||||
<input class="qty-inputs" type="hidden" name="product_quantityf" value="<?php echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1"; ?>" id="qty-input" min="<?php echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1"; ?>" />
|
||||
|
||||
<input name="product_id" type="hidden" value='<?php echo $product_details['_id']; ?>'/>
|
||||
<input name="product_id" type="hidden" value='<?php echo $product_details['_id']; ?>' />
|
||||
|
||||
<!-- <input name="product_quantity" type="number"/> -->
|
||||
<div class="modal-footer">
|
||||
|
@ -774,11 +777,29 @@ if (isset($_GET['id'])) {
|
|||
// April 3, 2024 Jun Jihad Apply Matrix
|
||||
var productPrice;
|
||||
var foundPrice = false;
|
||||
|
||||
|
||||
// if (priceMatrix.length > 0) {
|
||||
// for (var i = 0; i < priceMatrix.length; i++) {
|
||||
// for (var j = 0; j < priceMatrix[i].length; j++) {
|
||||
// if (quantityValue <= parseInt(priceMatrix[i][j].quantity)) {
|
||||
// productPrice = parseFloat(priceMatrix[i][j].price);
|
||||
// foundPrice = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (foundPrice) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if (priceMatrix.length > 0) {
|
||||
for (var i = 0; i < priceMatrix.length; i++) {
|
||||
for (var j = 0; j < priceMatrix[i].length; j++) {
|
||||
if (quantityValue <= parseInt(priceMatrix[i][j].quantity)) {
|
||||
var currentQuantity = parseFloat(priceMatrix[i][j].quantity);
|
||||
var nextQuantity = (j < priceMatrix[i].length - 1) ? parseFloat(priceMatrix[i][j + 1].quantity) : Infinity;
|
||||
|
||||
if (quantityValue >= currentQuantity && quantityValue < nextQuantity) {
|
||||
productPrice = parseFloat(priceMatrix[i][j].price);
|
||||
foundPrice = true;
|
||||
break;
|
||||
|
@ -789,10 +810,11 @@ if (isset($_GET['id'])) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!foundPrice) {
|
||||
productPrice = parseFloat(document.getElementById("productNewPrice") ? document.getElementById("productNewPrice").innerText : document.getElementById("productPrice").innerText);
|
||||
}
|
||||
}
|
||||
var productData = {
|
||||
product: {
|
||||
product_image: document.getElementById("mainProductImage").getAttribute('src'),
|
||||
|
@ -865,7 +887,7 @@ if (isset($_GET['id'])) {
|
|||
shipping_fee: shippingFee,
|
||||
};
|
||||
|
||||
console.log("Request data:", requestData);
|
||||
console.log("Request data:", requestData);
|
||||
// const token = '<?php echo $_SESSION["token"] ?>';
|
||||
xhr.open("POST", "https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/orders", true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json", );
|
||||
|
@ -875,7 +897,7 @@ if (isset($_GET['id'])) {
|
|||
if (xhr.status === 201) {
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
|
||||
console.log("Response:", response);
|
||||
console.log("Response:", response);
|
||||
|
||||
// Update the cart dynamically
|
||||
var cartList = document.querySelector(".eccart-pro-items");
|
||||
|
@ -945,24 +967,24 @@ if (isset($_GET['id'])) {
|
|||
}
|
||||
|
||||
function updateOrder(orderId, existingItemId) {
|
||||
var updateOrderXhr = new XMLHttpRequest();
|
||||
// const token = '<?php echo $_SESSION["token"] ?>';
|
||||
updateOrderXhr.open("PUT", `https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/orders/${orderId}/items/${existingItemId}`, true);
|
||||
updateOrderXhr.setRequestHeader("Content-Type", "application/json");
|
||||
updateOrderXhr.setRequestHeader("Authorization", "Bearer " + token);
|
||||
updateOrderXhr.onreadystatechange = function() {
|
||||
if (updateOrderXhr.readyState === 4) {
|
||||
if (updateOrderXhr.status === 200) {
|
||||
var response = JSON.parse(updateOrderXhr.responseText);
|
||||
console.log("Order updated:", response);
|
||||
var updateOrderXhr = new XMLHttpRequest();
|
||||
// const token = '<?php echo $_SESSION["token"] ?>';
|
||||
updateOrderXhr.open("PUT", `https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/orders/${orderId}/items/${existingItemId}`, true);
|
||||
updateOrderXhr.setRequestHeader("Content-Type", "application/json");
|
||||
updateOrderXhr.setRequestHeader("Authorization", "Bearer " + token);
|
||||
updateOrderXhr.onreadystatechange = function() {
|
||||
if (updateOrderXhr.readyState === 4) {
|
||||
if (updateOrderXhr.status === 200) {
|
||||
var response = JSON.parse(updateOrderXhr.responseText);
|
||||
console.log("Order updated:", response);
|
||||
|
||||
var cartItem = document.getElementById(`order_${response._id}`);
|
||||
var cartItem = document.getElementById(`order_${response._id}`);
|
||||
|
||||
if (cartItem) {
|
||||
var updatedQuantity = response.items[0].quantity;
|
||||
var totalAmount = response.items[0].price * updatedQuantity;
|
||||
// If the cart item already exists, update its content using innerHTML
|
||||
cartItem.innerHTML = `
|
||||
if (cartItem) {
|
||||
var updatedQuantity = response.items[0].quantity;
|
||||
var totalAmount = response.items[0].price * updatedQuantity;
|
||||
// If the cart item already exists, update its content using innerHTML
|
||||
cartItem.innerHTML = `
|
||||
<a href="shop-left-sidebar-col-4.php" class="sidekka_pro_img">
|
||||
<img src="${response.items[0].product.product_image}" alt="product">
|
||||
</a>
|
||||
|
@ -980,72 +1002,73 @@ if (isset($_GET['id'])) {
|
|||
<a href="#" class="removeCart" onclick="deleteOrder('${response._id}')">x</a>
|
||||
</div>
|
||||
`;
|
||||
document.getElementById(`qty-input-${response.items[0]._id}`).value = updatedQuantity;
|
||||
} else {
|
||||
// If the cart item doesn't exist, create a new one
|
||||
console.log("Error updating order:", updateOrderXhr.responseText);
|
||||
}
|
||||
document.getElementById(`qty-input-${response.items[0]._id}`).value = updatedQuantity;
|
||||
} else {
|
||||
// If the cart item doesn't exist, create a new one
|
||||
console.log("Error updating order:", updateOrderXhr.responseText);
|
||||
}
|
||||
|
||||
getLatestOrders();
|
||||
updateCartItemCount();
|
||||
document.getElementById("addToCartMessage").innerText = "Product added to cart!";
|
||||
setTimeout(function() {
|
||||
document.getElementById("addToCartMessage").innerText = "";
|
||||
}, 1000);
|
||||
} else {
|
||||
// Handle error response from the server
|
||||
console.log("Error response from the server");
|
||||
console.log(xhr.responseText); // Log the server's response
|
||||
}
|
||||
}
|
||||
};
|
||||
var existingQuantity = parseInt(existingOrder.items[0].quantity, 10);
|
||||
var newQuantity = parseInt(quantityValue, 10);
|
||||
var updatedQuantity = existingQuantity + newQuantity;
|
||||
getLatestOrders();
|
||||
updateCartItemCount();
|
||||
document.getElementById("addToCartMessage").innerText = "Product added to cart!";
|
||||
setTimeout(function() {
|
||||
document.getElementById("addToCartMessage").innerText = "";
|
||||
}, 1000);
|
||||
} else {
|
||||
// Handle error response from the server
|
||||
console.log("Error response from the server");
|
||||
console.log(xhr.responseText); // Log the server's response
|
||||
}
|
||||
}
|
||||
};
|
||||
var existingQuantity = parseInt(existingOrder.items[0].quantity, 10);
|
||||
var newQuantity = parseInt(quantityValue, 10);
|
||||
var updatedQuantity = existingQuantity + newQuantity;
|
||||
|
||||
// Check if the updated quantity exceeds the previous price matrix
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if the updated quantity exceeds the previous price matrix
|
||||
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++) {
|
||||
var currentQuantity = parseFloat(priceMatrix[i][j].quantity);
|
||||
var nextQuantity = (j < priceMatrix[i].length - 1) ? parseFloat(priceMatrix[i][j + 1].quantity) : Infinity;
|
||||
if (updatedQuantity >= currentQuantity && updatedQuantity < nextQuantity) {
|
||||
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;
|
||||
}
|
||||
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));
|
||||
|
||||
// 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);
|
||||
// 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 totalAmount = productPrice * updatedQuantity;
|
||||
var patchData = {
|
||||
total_amount: totalAmount
|
||||
};
|
||||
var totalAmount = productPrice * updatedQuantity;
|
||||
var patchData = {
|
||||
total_amount: totalAmount
|
||||
};
|
||||
|
||||
patchTotalAmountXhr.send(JSON.stringify(patchData));
|
||||
}
|
||||
patchTotalAmountXhr.send(JSON.stringify(patchData));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1542,14 +1565,14 @@ patchTotalAmountXhr.send(JSON.stringify(patchData));
|
|||
<div class="ec-pro-image">
|
||||
<!-- <a href="shop-left-sidebar-col-4.php" class="image"> -->
|
||||
<!-- 02-21-2024 Stacy changed link for image -->
|
||||
<a class="image" href="product-left-sidebar.php?id=<?php echo $similar_products[$pid]["_id"] ?>">
|
||||
<a class="image" href="product-left-sidebar.php?id=<?php echo $similar_products[$pid]["_id"] ?>">
|
||||
<img class="main-image" src="<?php echo $similar_products[$pid]["product_image"] ?>" />
|
||||
<img class="hover-image" src="<?php echo $similar_products[$pid]["product_image"] ?>" />
|
||||
</a>
|
||||
<!-- 02-21-2024 Stacy commented out -->
|
||||
<!-- <span class="percentage">20%</span> -->
|
||||
<!-- <span class="percentage">20%</span> -->
|
||||
<!-- <a href="#" class="quickview" data-link-action="quickview" title="Quick view" data-bs-toggle="modal" data-bs-target="#ec_quickview_modal"><i class="fi-rr-eye"></i></a> -->
|
||||
|
||||
|
||||
<!-- <div class="ec-pro-actions">
|
||||
<a href="compare.html" class="ec-btn-group compare" title="Compare"><i class="fi fi-rr-arrows-repeat"></i></a>
|
||||
<button title="Add To Cart" class="add-to-cart"><i class="fi-rr-shopping-basket"></i> Add To Cart</button>
|
||||
|
@ -1562,17 +1585,17 @@ patchTotalAmountXhr.send(JSON.stringify(patchData));
|
|||
<?php if (isset($similar_products[$pid]["sale_price"]) && $similar_products[$pid]["sale_price"] > 0) : ?>
|
||||
<button title="Add To Cart" onclick="popupAddToCart(`<?php echo htmlspecialchars(json_encode($similar_products[$pid]), ENT_QUOTES, 'UTF-8'); ?>`,`<?php echo htmlspecialchars($vendorOfProduct, ENT_QUOTES, 'UTF-8'); ?>`, `<?php echo isset($_SESSION['token']) ? $_SESSION['token'] : ''; ?>` , `<?php echo isset($_SESSION['email']) ? $_SESSION['email'] : ''; ?>` , `<?php echo isset($_SESSION['password']) ? $_SESSION['password'] : ''; ?>` , `<?php echo htmlspecialchars(json_encode($customer_data), ENT_QUOTES, 'UTF-8'); ?>`);" class="add-to-cart"><i class="fi-rr-shopping-basket"></i> Add To Cart</button>
|
||||
<a class="ec-btn-group wishlist" title="Wishlist" onclick="popupWishlist('<?php echo htmlspecialchars(json_encode($similar_products[$pid]), ENT_QUOTES, 'UTF-8'); ?>', '<?php echo htmlspecialchars(json_encode($customer_data), ENT_QUOTES, 'UTF-8'); ?>');"><i class="fi-rr-heart"></i></a>
|
||||
|
||||
|
||||
<?php elseif (isset($similar_products[$pid]["regular_price"]) && $similar_products[$pid]["regular_price"] != "") : ?>
|
||||
<button title="Add To Cart" onclick="popupAddToCart(`<?php echo htmlspecialchars(json_encode($similar_products[$pid]), ENT_QUOTES, 'UTF-8'); ?>`,`<?php echo htmlspecialchars($vendorOfProduct, ENT_QUOTES, 'UTF-8'); ?>`, `<?php echo isset($_SESSION['token']) ? $_SESSION['token'] : ''; ?>` , `<?php echo isset($_SESSION['email']) ? $_SESSION['email'] : ''; ?>` , `<?php echo isset($_SESSION['password']) ? $_SESSION['password'] : ''; ?>` , `<?php echo htmlspecialchars(json_encode($customer_data), ENT_QUOTES, 'UTF-8'); ?>`);" class="add-to-cart"><i class="fi-rr-shopping-basket"></i> Add To Cart</button>
|
||||
<a class="ec-btn-group wishlist" title="Wishlist" onclick="popupWishlist('<?php echo htmlspecialchars(json_encode($similar_products[$pid]), ENT_QUOTES, 'UTF-8'); ?>', '<?php echo htmlspecialchars(json_encode($customer_data), ENT_QUOTES, 'UTF-8'); ?>');"><i class="fi-rr-heart"></i></a>
|
||||
|
||||
|
||||
<?php else : ($similar_products[$pid]["regular_price"] == "" || $similar_products[$pid]["regular_price"] == null) ?>
|
||||
<a class="ec-btn-group wishlist" title="Wishlist" onclick="popupWishlist('<?php echo htmlspecialchars(json_encode($similar_products[$pid]), ENT_QUOTES, 'UTF-8'); ?>', '<?php echo htmlspecialchars(json_encode($customer_data), ENT_QUOTES, 'UTF-8'); ?>');"><i class="fi-rr-heart"></i></a>
|
||||
|
||||
|
||||
<?php endif; ?>
|
||||
<!-- 02-29-2024 Stacy disabling hover add to cart if there's no price -->
|
||||
|
||||
|
||||
<!-- <button title="Add To Cart" onclick="popupAddToCart(`<?php echo htmlspecialchars(json_encode($similar_products[$pid]), ENT_QUOTES, 'UTF-8'); ?>`,`<?php echo htmlspecialchars($vendorOfProduct, ENT_QUOTES, 'UTF-8'); ?>`, `<?php echo isset($_SESSION['token']) ? $_SESSION['token'] : ''; ?>` , `<?php echo isset($_SESSION['email']) ? $_SESSION['email'] : ''; ?>` , `<?php echo isset($_SESSION['password']) ? $_SESSION['password'] : ''; ?>` , `<?php echo htmlspecialchars(json_encode($customer_data), ENT_QUOTES, 'UTF-8'); ?>`);" class="add-to-cart"><i class="fi-rr-shopping-basket"></i> Add To Cart</button>
|
||||
<a class="ec-btn-group wishlist" title="Wishlist" onclick="popupWishlist('<?php echo htmlspecialchars(json_encode($similar_products[$pid]), ENT_QUOTES, 'UTF-8'); ?>', '<?php echo htmlspecialchars(json_encode($customer_data), ENT_QUOTES, 'UTF-8'); ?>');"><i class="fi-rr-heart"></i></a> -->
|
||||
</div>
|
||||
|
@ -1581,10 +1604,12 @@ patchTotalAmountXhr.send(JSON.stringify(patchData));
|
|||
</div>
|
||||
<div class="ec-pro-content">
|
||||
<!-- 02-21-2024 Stacy updated link for product name -->
|
||||
<!-- <h5 class="ec-pro-title"><a href="shop-left-sidebar-col-4.php?id=<?php #echo $similar_products[$pid]["_id"] ?>"><?php #echo $similar_products[$pid]["product_name"] ?></a></h5> -->
|
||||
<!-- <h5 class="ec-pro-title"><a href="shop-left-sidebar-col-4.php?id=<?php #echo $similar_products[$pid]["_id"]
|
||||
?>"><?php #echo $similar_products[$pid]["product_name"]
|
||||
?></a></h5> -->
|
||||
<h5 class="ec-pro-title"><a href="product-left-sidebar.php?id=<?php echo $similar_products[$pid]["_id"]; ?>"><?php echo $similar_products[$pid]["product_name"] ?></a></h5>
|
||||
<!-- 02-21-2024 Stacy updated link for product name -->
|
||||
|
||||
|
||||
<!-- 02-20-2024 Stacy commented ratings -->
|
||||
<!-- <div class="ec-pro-rating">
|
||||
<i class="ecicon eci-star fill"></i>
|
||||
|
@ -2008,8 +2033,8 @@ patchTotalAmountXhr.send(JSON.stringify(patchData));
|
|||
<script src="assets/js/newjs.js"></script>
|
||||
|
||||
<!-- 02-21-2024 Stacy added js link -->
|
||||
<?php
|
||||
if ($_SESSION["is_test"]==true) {
|
||||
<?php
|
||||
if ($_SESSION["is_test"] == true) {
|
||||
echo '<script src="assets/js/tester11.js"></script>';
|
||||
} else {
|
||||
echo '<script src="assets/js/produc3.js"></script>';
|
||||
|
|
Loading…
Reference in New Issue