added message if wishlist is empty

This commit is contained in:
gelonspr 2024-05-08 18:00:36 +08:00
parent 9e5694145a
commit 6efdc5f4dd
1 changed files with 203 additions and 199 deletions

View File

@ -174,240 +174,244 @@ if ($_SESSION["isVendor"] == true) {
</div>
<div class="row margin-minus-b-30">
<?php foreach ($customer['favorites']['products'] as $product) {
// raymart added vendorproduct feb 14 2024
$vendorOfProduct = getVendorbyId($product['vendor_api_id']);
?>
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-6 mb-6 pro-gl-content">
<div class="ec-product-inner">
<!-- raymart added style for checkboxes feb 19 2024 -->
<input type="checkbox" class="product-checkbox" style="width: 20px; height: 20px; "value="<?php echo $product["_id"]; ?>">
<div class="ec-pro-image-outer" style="max-width: 290px; height: 350px;">
<div class="ec-pro-image">
<a href="product-left-sidebar.php?id=<?php echo $product["_id"]; ?>" class="image">
<!-- <a href="shop-left-sidebar-col-4.php" class="image"> -->
<img loading="lazy" class="main-image" src="<?php echo $product["images"]; ?>" alt="Product" style="border: 1px solid #eeeeee; height: 330px; object-fit: cover;"/>
<!-- <img loading="lazy" class="hover-image" src="<?php echo $product["images"]; ?>" alt="Product" /> -->
</a>
<span class="ec-com-remove ec-remove-wishlist">
<a href="javascript:void(0)" class="remove-product" data-product-id="<?php echo $product["_id"]; ?>" id="removeItem<?php echo $product["_id"]; ?>">×</a>
</span>
<!-- raymart edit action feb 14 2024 -->
<div class="ec-pro-actions" style="bottom: -70px;">
<!-- <button title="Add To Cart" onclick="popupAddToCart(`<?php echo htmlspecialchars(json_encode($product), 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($product), ENT_QUOTES, 'UTF-8'); ?>', '<?php echo htmlspecialchars(json_encode($customer_data), ENT_QUOTES, 'UTF-8'); ?>');"><i class="fi-rr-heart"></i></a> -->
<?php if (isset($product["sale_price"]) && $product["sale_price"] > 0) : ?>
<?php
if (empty($customer['favorites']['products'])) {
echo '<div class="col-12 text-center fs-2"><p>No wishlist</p></div>'; // Display "No wishlist" message if wishlist is empty
} else {
foreach ($customer['favorites']['products'] as $product) {
// raymart added vendorproduct feb 14 2024
$vendorOfProduct = getVendorbyId($product['vendor_api_id']);
?>
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-6 mb-6 pro-gl-content">
<div class="ec-product-inner">
<!-- raymart added style for checkboxes feb 19 2024 -->
<input type="checkbox" class="product-checkbox" style="width: 20px; height: 20px; "value="<?php echo $product["_id"]; ?>">
<div class="ec-pro-image-outer" style="max-width: 290px; height: 350px;">
<div class="ec-pro-image">
<a href="product-left-sidebar.php?id=<?php echo $product["_id"]; ?>" class="image">
<!-- <a href="shop-left-sidebar-col-4.php" class="image"> -->
<img loading="lazy" class="main-image" src="<?php echo $product["images"]; ?>" alt="Product" style="border: 1px solid #eeeeee; height: 330px; object-fit: cover;"/>
<!-- <img loading="lazy" class="hover-image" src="<?php echo $product["images"]; ?>" alt="Product" /> -->
</a>
<span class="ec-com-remove ec-remove-wishlist">
<a href="javascript:void(0)" class="remove-product" data-product-id="<?php echo $product["_id"]; ?>" id="removeItem<?php echo $product["_id"]; ?>">×</a>
</span>
<!-- raymart edit action feb 14 2024 -->
<div class="ec-pro-actions" style="bottom: -70px;">
<!-- <button title="Add To Cart" onclick="popupAddToCart(`<?php echo htmlspecialchars(json_encode($product), 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($product), ENT_QUOTES, 'UTF-8'); ?>', '<?php echo htmlspecialchars(json_encode($customer_data), ENT_QUOTES, 'UTF-8'); ?>');"><i class="fi-rr-heart"></i></a> -->
<?php if (isset($product["sale_price"]) && $product["sale_price"] > 0) : ?>
<button title="Add To Cart" onclick="popupAddToCart(`<?php echo htmlspecialchars(json_encode($product), 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>
<?php elseif (isset($product["regular_price"]) && $product["regular_price"] != "") : ?>
<button title="Add To Cart" onclick="popupAddToCart(`<?php echo htmlspecialchars(json_encode($product), 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>
<?php elseif (isset($product["regular_price"]) && $product["regular_price"] != "") : ?>
<button title="Add To Cart" onclick="popupAddToCart(`<?php echo htmlspecialchars(json_encode($product), 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>
<?php else : ($product["regular_price"] == "" || $product["regular_price"] == null) ?>
<?php else : ($product["regular_price"] == "" || $product["regular_price"] == null) ?>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="ec-pro-content">
<h5 class="ec-pro-title"><a href="product-left-sidebar.php?id=<?php echo $product["_id"]; ?>"><?php echo $product["product_name"]; ?></a></h5>
<!-- <div class="ec-pro-rating">
<i class="ecicon eci-star fill"></i>
<i class="ecicon eci-star fill"></i>
<i class="ecicon eci-star fill"></i>
<i class="ecicon eci-star fill"></i>
<i class="ecicon eci-star"></i>
</div> -->
<!-- <div class="ec-pro-list-desc">Lorem Ipsum is simply dummy text of the
printing and typesetting industry. Lorem Ipsum is simply dutmmy text
ever since the 1500s, when an unknown printer took a galley.</div> -->
<?php if ($product['product_type'] === 'variable') {
$variation_products = getProductVariations($product['_id']);
if ($variation_products) {
$variation_details = json_decode($variation_products, true);
}
} ?>
<!-- <span class="ec-price">
<span class="old-price">$12.00 <?php echo $product["regular_price"]; ?></span>
<span class="new-price">$10.00</span>
</span> -->
<?php
if ($product['product_type'] === "simple") {
if (isset($product['sale_price']) && $product['sale_price'] > 0) {
echo '<span class="ec-price">';
echo '<span class="old-price">' . $product['regular_price'] . '</span>';
echo '<span class="new-price">' . $product['sale_price'] . '</span>';
echo '</span>';
} else {
echo '<span class="new-price">' . $product['regular_price'] . '</span>';
}
} elseif ($product['product_type'] === "variable") {
$lowest_regular_price = null;
$highest_regular_price = null;
$lowest_sale_price = null;
$highest_sale_price = null;
<div class="ec-pro-content">
<h5 class="ec-pro-title"><a href="product-left-sidebar.php?id=<?php echo $product["_id"]; ?>"><?php echo $product["product_name"]; ?></a></h5>
<!-- <div class="ec-pro-rating">
<i class="ecicon eci-star fill"></i>
<i class="ecicon eci-star fill"></i>
<i class="ecicon eci-star fill"></i>
<i class="ecicon eci-star fill"></i>
<i class="ecicon eci-star"></i>
</div> -->
<!-- <div class="ec-pro-list-desc">Lorem Ipsum is simply dummy text of the
printing and typesetting industry. Lorem Ipsum is simply dutmmy text
ever since the 1500s, when an unknown printer took a galley.</div> -->
<?php if ($product['product_type'] === 'variable') {
$variation_products = getProductVariations($product['_id']);
if ($variation_products) {
$variation_details = json_decode($variation_products, true);
}
} ?>
<!-- <span class="ec-price">
<span class="old-price">$12.00 <?php echo $product["regular_price"]; ?></span>
<span class="new-price">$10.00</span>
</span> -->
<?php
if ($product['product_type'] === "simple") {
if (isset($product['sale_price']) && $product['sale_price'] > 0) {
echo '<span class="ec-price">';
echo '<span class="old-price">' . $product['regular_price'] . '</span>';
echo '<span class="new-price">' . $product['sale_price'] . '</span>';
echo '</span>';
} else {
echo '<span class="new-price">' . $product['regular_price'] . '</span>';
}
} elseif ($product['product_type'] === "variable") {
$lowest_regular_price = null;
$highest_regular_price = null;
$lowest_sale_price = null;
$highest_sale_price = null;
if (isset($variation_details) && is_array($variation_details)) {
foreach ($variation_details as $index => $variation) {
$regular_price = isset($variation['regular_price']) ? $variation['regular_price'] : 0;
$sale_price = isset($variation['sale_price']) ? $variation['sale_price'] : 0;
if (isset($variation_details) && is_array($variation_details)) {
foreach ($variation_details as $index => $variation) {
$regular_price = isset($variation['regular_price']) ? $variation['regular_price'] : 0;
$sale_price = isset($variation['sale_price']) ? $variation['sale_price'] : 0;
// Update the minimum and maximum prices only if they are not null
if ($lowest_regular_price === null || $regular_price < $lowest_regular_price) {
$lowest_regular_price = $regular_price;
}
// Update the minimum and maximum prices only if they are not null
if ($lowest_regular_price === null || $regular_price < $lowest_regular_price) {
$lowest_regular_price = $regular_price;
}
if ($highest_regular_price === null || $regular_price > $highest_regular_price) {
$highest_regular_price = $regular_price;
}
if ($highest_regular_price === null || $regular_price > $highest_regular_price) {
$highest_regular_price = $regular_price;
}
if ($lowest_sale_price === null || $sale_price < $lowest_sale_price) {
$lowest_sale_price = $sale_price;
}
if ($lowest_sale_price === null || $sale_price < $lowest_sale_price) {
$lowest_sale_price = $sale_price;
}
if ($highest_sale_price === null || $sale_price > $highest_sale_price) {
$highest_sale_price = $sale_price;
if ($highest_sale_price === null || $sale_price > $highest_sale_price) {
$highest_sale_price = $sale_price;
}
}
}
}
// Display the range of prices based on the presence of sale prices
if ($lowest_sale_price !== null && $highest_sale_price !== null && $lowest_sale_price > 0 && $highest_sale_price > 0) {
echo '<span id="productPrice" class="new-price">' . '&#8369;' . $lowest_sale_price . ' - &#8369;' . $highest_sale_price . '</span>';
} elseif ($lowest_regular_price !== null && $highest_regular_price !== null) {
echo '<span id="productPrice" class="new-price">' . '&#8369;' . $lowest_regular_price . ' - &#8369;' . $highest_regular_price . '</span>';
// Display the range of prices based on the presence of sale prices
if ($lowest_sale_price !== null && $highest_sale_price !== null && $lowest_sale_price > 0 && $highest_sale_price > 0) {
echo '<span id="productPrice" class="new-price">' . '&#8369;' . $lowest_sale_price . ' - &#8369;' . $highest_sale_price . '</span>';
} elseif ($lowest_regular_price !== null && $highest_regular_price !== null) {
echo '<span id="productPrice" class="new-price">' . '&#8369;' . $lowest_regular_price . ' - &#8369;' . $highest_regular_price . '</span>';
}
}
}
?>
?>
</div>
</div>
</div>
</div>
<script>
customerId = '<?php echo $_SESSION['customerId']; ?>'
// Add event listener to remove button
document.addEventListener('DOMContentLoaded', function() {
var removeButtons = document.querySelectorAll('.remove-product');
removeButtons.forEach(function(removeButton) {
removeButton.addEventListener('click', function() {
var productId = removeButton.getAttribute('data-product-id');
removeProduct(productId);
<script>
customerId = '<?php echo $_SESSION['customerId']; ?>'
// Add event listener to remove button
document.addEventListener('DOMContentLoaded', function() {
var removeButtons = document.querySelectorAll('.remove-product');
removeButtons.forEach(function(removeButton) {
removeButton.addEventListener('click', function() {
var productId = removeButton.getAttribute('data-product-id');
removeProduct(productId);
});
});
var deleteButton = document.getElementById('delete-button');
deleteButton.addEventListener('click', function() {
var selectedProducts = [];
var checkboxes = document.querySelectorAll('.product-checkbox');
checkboxes.forEach(function(checkbox) {
if (checkbox.checked) {
selectedProducts.push(checkbox.value);
}
});
deleteProducts(selectedProducts);
});
});
var deleteButton = document.getElementById('delete-button');
deleteButton.addEventListener('click', function() {
var selectedProducts = [];
var checkboxes = document.querySelectorAll('.product-checkbox');
checkboxes.forEach(function(checkbox) {
if (checkbox.checked) {
selectedProducts.push(checkbox.value);
}
var selectAllButton = document.querySelector('#select-button');
selectAllButton.addEventListener('click', function() {
var selectedProducts = [];
var checkboxes = document.querySelectorAll('.product-checkbox');
// checkboxes.forEach(function(checkbox) {
// }
console.log('clicked')
for (let i = 0; i < checkboxes.length; i++ ) {
checkboxes[i].checked = selectAllButton.checked
// checkboxes[i].checked = true
}})
// Function to remove product
function removeProduct(productId) {
// Get all product IDs except the one to remove
var remainingProductIds = Array.from(document.querySelectorAll('.remove-product')).map(function(button) {
return button.getAttribute('data-product-id');
}).filter(function(id) {
return id !== productId;
});
deleteProducts(selectedProducts);
});
});
var selectAllButton = document.querySelector('#select-button');
selectAllButton.addEventListener('click', function() {
var selectedProducts = [];
var checkboxes = document.querySelectorAll('.product-checkbox');
// checkboxes.forEach(function(checkbox) {
// }
console.log('clicked')
for (let i = 0; i < checkboxes.length; i++ ) {
checkboxes[i].checked = selectAllButton.checked
// checkboxes[i].checked = true
}})
// Function to remove product
function removeProduct(productId) {
// Get all product IDs except the one to remove
var remainingProductIds = Array.from(document.querySelectorAll('.remove-product')).map(function(button) {
return button.getAttribute('data-product-id');
}).filter(function(id) {
return id !== productId;
});
// Make an AJAX request to update the favorites with the remaining products
var xhr = new XMLHttpRequest();
// xhr.open('PATCH', 'https://api.obanana.shop/api/v1/customers/' + customerId, true);
xhr.open('PATCH', 'https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' + customerId, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
// Product removed successfully, you can handle the UI update here if needed
console.log('Product removed successfully');
location.reload(); // Refresh the page after removing the product
} else {
// Handle error response
console.error('Error removing product:', xhr.responseText);
// Make an AJAX request to update the favorites with the remaining products
var xhr = new XMLHttpRequest();
// xhr.open('PATCH', 'https://api.obanana.shop/api/v1/customers/' + customerId, true);
xhr.open('PATCH', 'https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' + customerId, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
// Product removed successfully, you can handle the UI update here if needed
console.log('Product removed successfully');
location.reload(); // Refresh the page after removing the product
} else {
// Handle error response
console.error('Error removing product:', xhr.responseText);
}
}
}
};
// Construct data object with the remaining product IDs
var data = JSON.stringify({
favorites: {
products: remainingProductIds.map(function(id) {
// Find the product object with the corresponding ID
var remainingProduct = <?php echo json_encode($customer['favorites']['products']); ?>.find(function(product) {
return product['_id'] === id;
});
};
// Construct data object with the remaining product IDs
var data = JSON.stringify({
favorites: {
products: remainingProductIds.map(function(id) {
// Find the product object with the corresponding ID
var remainingProduct = <?php echo json_encode($customer['favorites']['products']); ?>.find(function(product) {
return product['_id'] === id;
});
// Return the entire product object
return remainingProduct;
})
}
});
xhr.send(data);
}
// Function to delete multiple products
function deleteProducts(productIds) {
var xhr = new XMLHttpRequest();
// xhr.open('PATCH', 'https://api.obanana.shop/api/v1/customers/' + customerId, true);
xhr.open('PATCH', 'https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' + customerId, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
console.log('Products removed successfully');
location.reload();
} else {
console.error('Error removing products:', xhr.responseText);
// Return the entire product object
return remainingProduct;
})
}
}
};
var remainingProductIds = Array.from(document.querySelectorAll('.remove-product')).map(function(button) {
return button.getAttribute('data-product-id');
}).filter(function(id) {
return !productIds.includes(id);
});
var data = JSON.stringify({
favorites: {
products: remainingProductIds.map(function(id) {
var remainingProduct = <?php echo json_encode($customer['favorites']['products']); ?>.find(function(product) {
return product['_id'] === id;
});
return remainingProduct;
})
}
});
xhr.send(data);
}
});
xhr.send(data);
}
// Function to delete multiple products
function deleteProducts(productIds) {
var xhr = new XMLHttpRequest();
// xhr.open('PATCH', 'https://api.obanana.shop/api/v1/customers/' + customerId, true);
xhr.open('PATCH', 'https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/customers/' + customerId, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
console.log('Products removed successfully');
location.reload();
} else {
console.error('Error removing products:', xhr.responseText);
}
}
};
var remainingProductIds = Array.from(document.querySelectorAll('.remove-product')).map(function(button) {
return button.getAttribute('data-product-id');
}).filter(function(id) {
return !productIds.includes(id);
});
var data = JSON.stringify({
favorites: {
products: remainingProductIds.map(function(id) {
var remainingProduct = <?php echo json_encode($customer['favorites']['products']); ?>.find(function(product) {
return product['_id'] === id;
});
return remainingProduct;
})
}
});
xhr.send(data);
}
</script>
<?php } ?>
<?php } }?>
</div>
</div>