Compare commits

..

2 Commits

4 changed files with 277 additions and 33 deletions

View File

@ -190,7 +190,61 @@ if($_SESSION["user_type"]!="admin"){
const array = new Array(productData)
console.log(array)
// const parseJs =JSON.parse(productData)
function searchProduct(e){
function searchProduct(e) {
const searchInput = document.getElementById('searchProduct');
const productWrap = document.getElementById('productWrap');
// Clear previous search results
productWrap.innerHTML = '';
// Get search query and ensure it's lowercase
const query = searchInput.value.trim().toLowerCase();
// Filter products based on search query
const filteredProducts = array[0].filter(product => {
return product.product_name.toLowerCase().includes(query);
});
if (filteredProducts.length > 0) {
// Display filtered products
filteredProducts.forEach(prod => {
const productImage = prod.images.split(',') ?? [];
const image = productImage[0] ?
`<img class="img-fluid" src="${productImage[0]}" alt="product image" style="object-fit: cover; width: 100%; height: 100%;" />` :
`<img class="img-fluid rounded-circle" src="https://api.obanana.com/images/storage/web_images/1710214273217-no_image.png" alt="placeholder image" style="object-fit: cover; width: 100%; height: 100%;" />`;
const card = document.createElement('div');
card.classList.add('col-lg-3', 'col-md-4', 'col-sm-6');
card.innerHTML = `
<div class="card-wrapper">
<div class="card-container">
<div class="card-top">
<div class="image-container" style="height: 300px;">
${image}
</div>
</div>
<div class="card-bottom">
<h3>${prod.product_name}</h3>
<p>${prod.regular_price}</p>
</div>
<div class="card-action">
<div class="card-edit" onclick="editProduct('${prod._id}');"><i class="mdi mdi-circle-edit-outline"></i></div>
<div class="card-preview"><i class="mdi mdi-eye-outline"></i></div>
<div class="card-remove" onclick="deleteProduct('${prod._id}');"><i class="mdi mdi mdi-delete-outline"></i></div>
</div>
</div>
</div>
`;
productWrap.appendChild(card);
});
} else {
// Display message if no products found
productWrap.innerHTML = `<p style="padding-top:10px; padding-left:20px;">No Product Found.</p>`;
}
}
const search = document.getElementById('searchProduct');
search.addEventListener("input", searchProduct);
/* function searchProduct(e){
const searchInput = document.getElementById('searchProduct')
let search = []
@ -255,7 +309,7 @@ if($_SESSION["user_type"]!="admin"){
// console.log(search)
}
const search = document.getElementById('searchProduct')
search.addEventListener("input", searchProduct)
search.addEventListener("input", searchProduct) */
</script>
<!-- 3-18-24 raymart add function for search bar -->
<!-- <div class="row">

View File

@ -487,12 +487,13 @@ if (isset($_GET['id'])) {
<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
$product_price = (!empty($product_details['sale_price'])) ? $product_details['sale_price'] : $product_details['regular_price'] ;
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 '" id="qty-input" />';
echo '" id="qty-input" oninput="handleInput()" />';
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>';
@ -504,7 +505,7 @@ if (isset($_GET['id'])) {
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 '" id="qty-input" />';
echo '" id="qty-input" oninput="handleInput()" />';
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>';
echo '<div> <div id="addToCartMessage" style="padding-left:45px;"></div> <button class="btn btn-primary" id="addToCartButton" style="text-wrap:nowrap; background:#ffaa00; margin-left:55px;"><i class="fi-rr-shopping-bag" style="font-size:20px; margin-bottom:-3px; margin-right:10px;"></i>Add To Cart</button></div>';
@ -626,12 +627,120 @@ if (isset($_GET['id'])) {
</div> -->
</div>
<script>
function increment() {
/* 04-18-24 raymart added functioning the quantity to handle if the product has price matrix */
function handleInput(action) {
var qtyInput = document.getElementById('qty-input');
qtyInput.value = parseInt(qtyInput.value) + 1;
var currentQuantity = parseInt(qtyInput.value);
var minimumOrder = <?php echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1"; ?>;
/* default to quantity 1 if input is empty */
if (!currentQuantity || isNaN(currentQuantity)) {
currentQuantity = 1;
}
/* default to minimum quantity if the product has minimun order */
if (currentQuantity < minimumOrder) {
currentQuantity = minimumOrder;
console.log("The minimum order quantity is " + minimumOrder);
}
/* Ensure the quantity never goes below 1 */
if (action === 'increment') {
currentQuantity += 1;
} else if (action === 'decrement' && currentQuantity > 1) {
currentQuantity -= 1;
}
currentQuantity = Math.max(currentQuantity, 1);
qtyInput.value = currentQuantity;
var handlePrice = document.getElementById('productNewPrice') || document.getElementById('productPrice');
var product_price = '<?php echo $product_price; ?>';
var priceMatrices = <?php echo (!empty($product_details['price_matrix'])) ? json_encode($product_details['price_matrix']) : "[]"; ?>;
var foundPrice = false;
for (var m = 0; m < priceMatrices.length; m++) {
var priceMatrix = priceMatrices[m];
for (var i = 0; i < priceMatrix.length; i++) {
var matrixQuantity = parseFloat(priceMatrix[i].quantity);
var nextMatrixQuantity = (i < priceMatrix.length - 1) ? parseFloat(priceMatrix[i + 1].quantity) : Infinity;
if (currentQuantity >= matrixQuantity && currentQuantity < nextMatrixQuantity) {
var unitPrice = parseFloat(priceMatrix[i].price);
handlePrice.innerText = unitPrice.toFixed(2).toString().replace(/\.00$/, '');
foundPrice = true;
break;
}
}
if (foundPrice) {
break;
}
}
if (!foundPrice) {
// Handle when quantity exceeds the highest price matrix
var lastMatrix = priceMatrices[priceMatrices.length - 1];
var highestQuantity = parseFloat(lastMatrix[lastMatrix.length - 1].quantity);
if (currentQuantity >= highestQuantity) {
var highestPrice = parseFloat(lastMatrix[lastMatrix.length - 1].price);
handlePrice.innerText = highestPrice.toFixed(2).replace(/\.00$/, '');
foundPrice = true;
}
}
// If original price is within the quantity range
if (!foundPrice) {
handlePrice.innerText = product_price;
}
}
function decrement() {
function increment() {
var qtyInput = document.getElementById('qty-input');
var currentQuantity = parseInt(qtyInput.value);
currentQuantity++;
qtyInput.value = currentQuantity;
var incrementPrice;
if (document.getElementById('productNewPrice')) {
incrementPrice = document.getElementById('productNewPrice');
} else {
incrementPrice = document.getElementById('productPrice');
}
// var productPrice = document.getElementById('productPrice');
var product_price = '<?php echo $product_price; ?>';
var foundPrice = false;
var priceMatrix = <?php echo (!empty($product_details['price_matrix'])) ? json_encode($product_details['price_matrix']) : "[]"; ?>;
/* to determine if regular price or price matrix but it depends to the quantity */
if (priceMatrix.length > 0) {
for (var i = 0; i < priceMatrix.length; i++) {
for (var j = 0; j < priceMatrix[i].length; j++) {
var matrixQuantity = parseFloat(priceMatrix[i][j].quantity);
var nextMatrixQuantity = (j < priceMatrix[i].length - 1) ? parseFloat(priceMatrix[i][j + 1].quantity) : Infinity;
if (currentQuantity >= matrixQuantity && currentQuantity < nextMatrixQuantity) {
var regularPrice = parseFloat(priceMatrix[i][j].price);
var nextPrice = (j < priceMatrix[i].length - 1) ? parseFloat(priceMatrix[i][j + 1].price) : product_price;
var unitPrice = regularPrice;
incrementPrice.innerText = parseFloat(unitPrice.toFixed(2)).toString(); // Convert to floating-point number and then to string
foundPrice = true;
break;
}
}
if (foundPrice) {
break;
}
}
}
}
/* function increment() {
var qtyInput = document.getElementById('qty-input');
qtyInput.value = parseInt(qtyInput.value) + 1;
} */
/* function decrement() {
var qtyInput = document.getElementById('qty-input');
var currentQuantity = parseInt(qtyInput.value);
@ -646,7 +755,64 @@ if (isset($_GET['id'])) {
qtyInput.value = currentQuantity - 1;
}
<?php endif; ?>
} */
function decrement() {
var qtyInput = document.getElementById('qty-input');
var currentQuantity = parseInt(qtyInput.value);
var minimumOrder = <?php echo (!empty($product_details['minimum_order'])) ? $product_details['minimum_order'] : "1"; ?>;
if (currentQuantity <= minimumOrder) {
console.log("The minimum order quantity is " + minimumOrder);
return;
}
if (currentQuantity > 1) {
currentQuantity--;
} else {
return; // Don't decrement further if quantity is already 1
}
qtyInput.value = currentQuantity;
var decrementPrice;
if (document.getElementById('productNewPrice')) {
decrementPrice = document.getElementById('productNewPrice');
} else {
decrementPrice = document.getElementById('productPrice');
}
// var productPrice = document.getElementById('productPrice');
var product_price = '<?php echo $product_price; ?>';
var foundPrice = false;
var priceMatrix = <?php echo (!empty($product_details['price_matrix'])) ? json_encode($product_details['price_matrix']) : "[]"; ?>;
/* to determine if regular price or price matrix but it depends to the quantity */
if (priceMatrix.length > 0) {
for (var i = 0; i < priceMatrix.length; i++) {
for (var j = 0; j < priceMatrix[i].length; j++) {
var matrixQuantity = parseFloat(priceMatrix[i][j].quantity);
var nextMatrixQuantity = (j < priceMatrix[i].length - 1) ? parseFloat(priceMatrix[i][j + 1].quantity) : Infinity;
if (currentQuantity >= matrixQuantity && currentQuantity < nextMatrixQuantity) {
var regularPrice = parseFloat(priceMatrix[i][j].price);
var nextPrice = (j < priceMatrix[i].length - 1) ? parseFloat(priceMatrix[i][j + 1].price) : product_price;
var unitPrice = regularPrice;
decrementPrice.innerText = parseFloat(unitPrice.toFixed(2)).toString(); /* Convert to floating-point number and then to string */
foundPrice = true;
break;
} else if (currentQuantity < matrixQuantity) {
/* If current quantity is less than the minimum in the price matrix, display the regular price */
decrementPrice.innerText = parseFloat(product_price).toFixed(2).replace(/\.00$/, ''); /* Remove trailing .00 */
foundPrice = true;
break;
}
}
if (foundPrice) {
break;
}
}
}
}
/* 04-18-24 raymart added functioning the quantity to handle if the product has price matrix */
<?php
@ -772,7 +938,22 @@ if (isset($_GET['id'])) {
if (parseInt(quantityValue) < minimumOrder) {
quantityValue = minimumOrder;
alert("The minimum order quantity is " + minimumOrder);
}
} /* else {
if (priceMatrix.length > 0) {
var selectedPrice = null;
for (var i = 0; i < priceMatrix.length; i++) {
if (parseInt(priceMatrix[i].quantity) === parseInt(quantityValue)) {
selectedPrice = priceMatrix[i].price;
break;
}
}
if (selectedPrice !== null) {
document.getElementById("price-display").innerText = "Price: $" + selectedPrice;
} else {
document.getElementById("price-display").innerText = "Price not available for this quantity";
}
}
} */
// April 3, 2024 Jun Jihad Apply Matrix
var productPrice;

View File

@ -276,11 +276,28 @@ $products = productList();
<!-- 03-11-2024 Stacy added pagination for vendor -->
<!-- Ec Pagination Start -->
<div class="pagination mt-3">
<?php
for ($i = 1; $i <= $totalPages; $i++) {
echo "<a href='?page=$i' class='" . ($currentpage == $i ? 'active' : '') . "'>$i</a>";
<?php
$start = max(1, $currentpage - 2);
$end = min($totalPages, $start + 4);
if ($start > 1) {
echo "<a href='?page=1'>1</a>";
if ($start > 2) {
echo "<span>&nbsp;...&nbsp;</span>";
}
}
?>
for ($i = $start; $i <= $end; $i++) {
echo "<a href='?page=$i' class='" . ($currentpage == $i ? 'active' : '') . "'>$i</a>&nbsp;";
}
if ($end < $totalPages) {
if ($end < $totalPages - 1) {
echo "<span>&nbsp;...&nbsp;</span>";
}
echo "<a href='?page=$totalPages'>$totalPages</a>";
}
?>
</div>
<!-- Ec Pagination End -->
</div>

View File

@ -21,12 +21,6 @@ if ($_SESSION["userId"] <> "") {
$_SESSION["isLoggedIn"] = false;
header("location: login.php");
}
if ($_SESSION["isCustomer"] == true) {
header("location: user-profile.php");
}
?>
<!DOCTYPE html>
<html lang="en">
@ -226,7 +220,7 @@ if ($_SESSION["isCustomer"] == true) {
</div>
<div class="col-md-6 col-sm-12">
<div class="ec-vendor-detail-block ec-vendor-block-contact space-bottom-30">
<h6>Contact nubmer</h6>
<h6>Contact number</h6>
<ul>
<li style="padding:3%"><strong><?php echo $vendorData["phone"] ?></strong></li>
</ul>
@ -322,7 +316,7 @@ if ($_SESSION["isCustomer"] == true) {
</label>
</div>
<div class="selectWrap" style="display: flex; justify-content: center; align-items: center; width: 50%;">
<div class="selectWrap" style="display: flex; justify-content: center; align-items: center; width: 50%; margin-left:-20px;">
<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,19 +524,17 @@ if ($_SESSION["isCustomer"] == true) {
<div class="card-body">
<div class="container">
<div class="row">
<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 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>
</div>