Fix Variable and Variation Bugs

This commit is contained in:
Jun Barroga 2024-04-23 09:38:06 +08:00
parent 2ba801d77d
commit 5f1aa3ab36
2 changed files with 34 additions and 11 deletions

View File

@ -73,12 +73,12 @@ if (isset($_SESSION["token"])) {
$issued_at_time = $token_data->iat;
$expiration_time = $token_data->exp;
$renewal_time = $issued_at_time + 3300;
$renewal_time = $issued_at_time + 3000;
if (time() >= $renewal_time || time() >= $expiration_time) {
header("Location: token-renew.php");
exit;
}
// if (time() >= $renewal_time || time() >= $expiration_time) {
// header("Location: token-renew.php");
// exit;
// }
}
// $token = loginRenew($_SESSION["email"], $_SESSION["password"], $token);
// $_SESSION["token"] = $token;
@ -114,7 +114,7 @@ if (isset($_SESSION["token"])) {
<!-- FAVICON -->
<link href="assets/img/favicon.png" rel="shortcut icon" />
<script>
<!-- <script>
function renewToken() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "token-renew.php", true);
@ -125,12 +125,33 @@ if (isset($_SESSION["token"])) {
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> -->
<script>
function renewToken() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "token-renew.php", true);
xhr.send();
console.log("Token renewed at: " + new Date().toLocaleString());
}
setInterval(function() {
var currentTime = <?php echo time(); ?>;
var renewalTime = <?php echo $renewal_time; ?>;
var expirationTime = <?php echo $expiration_time; ?>;
console.log("Current Time: " + new Date(currentTime * 1000).toLocaleString());
console.log("Renewal Time: " + new Date(renewalTime * 1000).toLocaleString());
console.log("Expiration Time: " + new Date(expirationTime * 1000).toLocaleString());
if (currentTime >= renewalTime || currentTime >= expirationTime) {
console.log("Renewing token...");
renewToken();
}
}, 60000);
</script>
</head>
<body class="ec-header-fixed ec-sidebar-fixed ec-sidebar-dark ec-header-light" id="body">
@ -214,6 +235,7 @@ if (isset($_SESSION["token"])) {
?>
<?php echo $_SESSION["token"] ?><br>
<?php $real_time = date('Y-m-d H:i:s', $expiration_time); echo $real_time?>
<?php // echo $_SESSION["email"] ?> <br>
<?php // echo "Updated token: " . $token; ?>
<?php // echo $_SESSION["password"] ?>

View File

@ -408,7 +408,7 @@ if (isset($_GET['id'])) {
<div class="ec-pro-variation-content">
<ul class="eccart-pro-items">
<?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';
$main_product_image = isset($product_details["images"]) ? $product_details["images"] : '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'); ?>)">
<li style="width: 100px; height: 100px">
@ -421,7 +421,7 @@ if (isset($_GET['id'])) {
<?php
foreach ($variation_details as $index => $variation) {
$variationImage = isset($variation["product_image"]) ? $variation["product_image"] : 'https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg';
$variationImage = isset($variation["images"]) ? $variation["images"] : 'https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg';
?>
<a href="javascript:void(0);" onclick="selectVariation(<?php echo htmlspecialchars(json_encode($variation), ENT_QUOTES, 'UTF-8'); ?>)">
<li style="width: 100px; height: 100px">
@ -447,10 +447,11 @@ if (isset($_GET['id'])) {
document.getElementById("shortDescription").innerHTML = variation.product_description;
document.getElementById("productTitle").innerText = variation.product_name;
document.getElementById("product_Id").value = variation._id;
var productImage = variation.product_image || 'https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg';
var productImage = variation.images || 'https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg';
document.getElementById('mainProductImage').src = productImage;
document.getElementById('mainProductImage').classList.remove('zoom-image-hover');
$('.zoom-image-hover').zoom();
document.getElementById("productTitlemodal").innerText = variation.product_name;
document.getElementById('mainProductImagemodal').src = productImage;