Skip to content

Commit

Permalink
Merge pull request #59 from TEAM-7-SAD/Remove-the-None-badge
Browse files Browse the repository at this point in the history
Remove the None badge
  • Loading branch information
Carl-Tabuso authored Jul 5, 2024
2 parents e6eb017 + 57beb81 commit 76146c1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 28 deletions.
7 changes: 4 additions & 3 deletions src/add_to_order_cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
$quantity = $_POST['quantity'];
$price = $_POST['price'];

// Exclude default variations
$servingOrType = $servingOrType === 'Default' ? '' : $servingOrType;
$flavorOrSize = $flavorOrSize === 'Default' ? '' : $flavorOrSize;
// Exclude default and none variations
$servingOrType = ($servingOrType === 'Default' || $servingOrType === 'None') ? '' : $servingOrType;
$flavorOrSize = ($flavorOrSize === 'Default' || $flavorOrSize === 'None') ? '' : $flavorOrSize;


$orderItem = [
// 'product_id' => $productId,
Expand Down
73 changes: 48 additions & 25 deletions src/get-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@
// Output food products
while($row = $foodResult->fetch_assoc()) {
$image = !empty($row['image']) ? $row['image'] : 'uploads/coffee-img-placeholder.png';
$serving = !empty($row['serving']) ? $row['serving'] : 'None';
$flavor = !empty($row['flavor']) ? $row['flavor'] : 'None';
echo '<div class="col">';
echo '<a href="#" class="list-group-item" data-bs-toggle="modal" data-bs-target="#product" data-product-id="' . $row['item_id'] . '" data-product-type="food" data-product-name="' . $row['item_name'] . '" data-product-serving="' . $row['serving'] . '" data-product-flavor="' . $row['flavor'] . '" data-product-price="' . $row['price'] . '">';
echo '<a href="#" class="list-group-item" data-bs-toggle="modal" data-bs-target="#product" data-product-id="' . $row['item_id'] . '" data-product-type="food" data-product-name="' . $row['item_name'] . '" data-product-serving="' . $serving . '" data-product-flavor="' . $flavor . '" data-product-price="' . $row['price'] . '">';
echo '<div class="card h-100 bg-white shadow-sm rounded-4 zoom-on-hover" style="min-height: 200px">';
echo '<div class="container">';
echo '<div class="row">';
echo '<div class="text-capitalize pt-2">';
if (!empty($row['serving'])) {
echo '<span class="badge text-bg-medium-brown rounded-1 text-wrap">' . $row['serving'] . '</span> ';
if ($serving !== 'None') {
echo '<span class="badge text-bg-medium-brown rounded-1 text-wrap">' . $serving . '</span> ';
}
if (!empty($row['flavor'])) {
echo '<span class="badge text-bg-carbon-grey rounded-1 text-wrap">' . $row['flavor'] . '</span><br> ';
if ($flavor !== 'None') {
echo '<span class="badge text-bg-carbon-grey rounded-1 text-wrap">' . $flavor . '</span><br> ';
}
echo '</div>';
echo '<div class="col px-4">';
Expand Down Expand Up @@ -92,18 +94,20 @@
// Output drink products
while($row = $drinkResult->fetch_assoc()) {
$image = !empty($row['image']) ? $row['image'] : 'uploads/coffee-img-placeholder.png';
$type = !empty($row['type']) ? $row['type'] : 'None';
$size = !empty($row['size']) ? $row['size'] : 'None';
echo '<div class="col">';
echo '<a href="#" class="list-group-item" data-bs-toggle="modal" data-bs-target="#product" data-product-id="' . $row['item_id'] . '" data-product-type="drink" data-product-name="' . $row['item_name'] . '" data-product-type-var="' . $row['type'] . '" data-product-size="' . $row['size'] . '" data-product-price="' . $row['price'] . '">';
echo '<a href="#" class="list-group-item" data-bs-toggle="modal" data-bs-target="#product" data-product-id="' . $row['item_id'] . '" data-product-type="drink" data-product-name="' . $row['item_name'] . '" data-product-type-var="' . $type . '" data-product-size="' . $size . '" data-product-price="' . $row['price'] . '">';
echo '<div class="card h-100 bg-white shadow-sm rounded-4 zoom-on-hover" style="min-height: 200px">';
echo '<div class="container">';
echo '<div class="row">';

echo '<div class="text-capitalize pt-2">';
if (!empty($row['type'])) {
echo '<span class="badge text-bg-medium-brown rounded-1 text-wrap">' . $row['type'] . '</span> ';
if ($type !== 'None') {
echo '<span class="badge text-bg-medium-brown rounded-1 text-wrap">' . $type . '</span> ';
}
if (!empty($row['size'])) {
echo '<span class="badge text-bg-carbon-grey rounded-1 text-wrap">' . $row['size'] . 'oz' . '</span><br> ';
if ($size !== 'None') {
echo '<span class="badge text-bg-carbon-grey rounded-1 text-wrap">' . $size . 'oz' . '</span><br> ';
}
echo '</div>';
echo '<div class="col px-4">';
Expand Down Expand Up @@ -134,6 +138,7 @@
}
?>


<style>
/* Hide the spinner arrows */
input[type="number"]::-webkit-inner-spin-button,
Expand All @@ -146,6 +151,10 @@
/* Firefox */
-moz-appearance: textfield;
}
.d-none {
display: none !important;
}

</style>

<!-- Modal for Product Variations -->
Expand All @@ -165,6 +174,8 @@
<input type="hidden" name="price" id="product_price">
<input type="hidden" id="defaultServingOrType" value="">
<input type="hidden" id="defaultFlavorOrSize" value="">
<input type="hidden" id="noneServingOrType" value="">
<input type="hidden" id="noneFlavorOrSize" value="">

<div class="mb-4">
<label for="servingOrType" class="col-form-label fw-medium text-carbon-grey mb-2">Serving/Type:</label><br/>
Expand Down Expand Up @@ -243,45 +254,58 @@
var defaultServingOrType = 'Default';
var defaultFlavorOrSize = 'Default';

var noneServingOrType = 'None';
var noneFlavorOrSize = 'None';

var servingOrTypeSet = new Set();
var flavorOrSizeSet = new Set();

data.forEach(function(variation) {
if (variation.servingOrType !== defaultServingOrType) {
if (variation.servingOrType !== defaultServingOrType && variation.servingOrType !== noneServingOrType) {
servingOrTypeSet.add(variation.servingOrType);
}
if (variation.flavorOrSize !== defaultFlavorOrSize) {
if (variation.flavorOrSize !== defaultFlavorOrSize && variation.flavorOrSize !== noneFlavorOrSize) {
flavorOrSizeSet.add(variation.flavorOrSize);
}
});

if (servingOrTypeSet.size > 0) {
servingOrTypeSet.forEach(function(servingOrType) {
$('#servingOrTypeGroup').append('<button type="button" class="btn btn-sm btn-outline-product text-capitalize fw-semibold rounded-4">' + servingOrType + '</button>');
var buttonHtml = '<button type="button" class="btn btn-sm btn-outline-product text-capitalize fw-semibold rounded-4">' + servingOrType + '</button>';
if (servingOrType === noneServingOrType) {
buttonHtml = '<button type="button" class="btn btn-sm btn-outline-product text-capitalize fw-semibold rounded-4 d-none active">' + servingOrType + '</button>';
}
$('#servingOrTypeGroup').append(buttonHtml);
});
} else {
$('#servingOrTypeGroup').append('<span class="text-carbon-grey font-13 fst-italic">No variations available</span>');
}

if (flavorOrSizeSet.size > 0) {
flavorOrSizeSet.forEach(function(flavorOrSize) {
$('#flavorOrSizeGroup').append('<button type="button" class="btn btn-sm btn-outline-product text-capitalize fw-semibold rounded-4">' + flavorOrSize + '</button>');
var buttonHtml = '<button type="button" class="btn btn-sm btn-outline-product text-capitalize fw-semibold rounded-4">' + flavorOrSize + '</button>';
if (flavorOrSize === noneFlavorOrSize) {
buttonHtml = '<button type="button" class="btn btn-sm btn-outline-product text-capitalize fw-semibold rounded-4 d-none active">' + flavorOrSize + '</button>';
}
$('#flavorOrSizeGroup').append(buttonHtml);
});
} else {
$('#flavorOrSizeGroup').append('<span class="text-carbon-grey font-13 fst-italic">No variations available</span>');
}

$('#defaultServingOrType').val(defaultServingOrType);
$('#defaultFlavorOrSize').val(defaultFlavorOrSize);
$('#noneServingOrType').val(noneServingOrType);
$('#noneFlavorOrSize').val(noneFlavorOrSize);

if ($('#servingOrTypeGroup button').length > 0) {
$('#servingOrTypeGroup button:first-child').addClass('active');
$('#servingOrTypeGroup button:not(.d-none):first-child').addClass('active');
} else {
$('#serving_or_type').val(defaultServingOrType);
}

if ($('#flavorOrSizeGroup button').length > 0) {
$('#flavorOrSizeGroup button:first-child').addClass('active');
$('#flavorOrSizeGroup button:not(.d-none):first-child').addClass('active');
} else {
$('#flavor_or_size').val(defaultFlavorOrSize);
}
Expand Down Expand Up @@ -326,14 +350,12 @@
});

$('#quantityInput').on('keypress', function(event) {
// Prevent non-numeric input
if (!/[0-9]/.test(String.fromCharCode(event.which))) {
event.preventDefault();
}
});

$('#quantityInput').on('paste', function(event) {
// Prevent pasting non-numeric values
var clipboardData = event.originalEvent.clipboardData.getData('text');
if (!/^\d+$/.test(clipboardData)) {
event.preventDefault();
Expand All @@ -349,8 +371,8 @@ function validateQuantity() {
}

function updatePrice() {
var selectedServingOrType = $('#servingOrTypeGroup .btn.active').text() || $('#defaultServingOrType').val();
var selectedFlavorOrSize = $('#flavorOrSizeGroup .btn.active').text() || $('#defaultFlavorOrSize').val();
var selectedServingOrType = $('#servingOrTypeGroup .btn.active').text() || $('#defaultServingOrType').val() || $('#noneServingOrType').val();
var selectedFlavorOrSize = $('#flavorOrSizeGroup .btn.active').text() || $('#defaultFlavorOrSize').val() || $('#noneFlavorOrSize').val();
var quantity = parseInt($('#quantityInput').val(), 10);

var selectedVariation = productData.find(function(variation) {
Expand All @@ -375,14 +397,13 @@ function addToCart() {
let productId = $('#product').data('product-id');
let productType = $('#product').data('product-type');
let productName = $('#productName').text();
let servingOrType = $('#servingOrTypeGroup .active').text() || $('#defaultServingOrType').val();
let flavorOrSize = $('#flavorOrSizeGroup .active').text() || $('#defaultFlavorOrSize').val();
let servingOrType = $('#servingOrTypeGroup .active').text() || $('#defaultServingOrType').val() || $('#noneServingOrType').val();
let flavorOrSize = $('#flavorOrSizeGroup .active').text() || $('#defaultFlavorOrSize').val() || $('#noneFlavorOrSize').val();
let quantity = $('#quantityInput').val();
let price = $('#priceDisplay').val();

// Exclude default variations from being added to the cart
if (servingOrType === 'Default') servingOrType = '';
if (flavorOrSize === 'Default') flavorOrSize = '';
if (servingOrType === 'Default' || servingOrType === 'None') servingOrType = '';
if (flavorOrSize === 'Default' || flavorOrSize === 'None') flavorOrSize = '';

$.ajax({
url: 'add_to_order_cart.php',
Expand Down Expand Up @@ -444,6 +465,8 @@ function calculateSubtotal() {
}
});
}


});
</script>

Expand Down

0 comments on commit 76146c1

Please sign in to comment.