Skip to content

Commit

Permalink
Merge pull request #62 from TEAM-7-SAD/last-pr-bago-magisa
Browse files Browse the repository at this point in the history
Change input field of tendered amount from 21 to 10,quantity input ma…
  • Loading branch information
Carl-Tabuso authored Jul 5, 2024
2 parents 1900fa6 + bb22efd commit f08d447
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
96 changes: 48 additions & 48 deletions src/get-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
</div>
<hr>
<div class="mb-1">
<label for="quantityInput" class="col-form-label fw-medium text-carbon-grey">Quantity:</label>
<label for="quantityInput" class="col-form-label fw-medium text-carbon-grey">Quantity:</label max="10">
<div class="input-group mt-2 mb-3">
<button class="btn btn-lg btn-outline-carbon-grey input-group-text fw-bold py-3 px-5" type="button" id="quantityMinus">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-dash-lg" viewBox="0 0 16 16">
Expand Down Expand Up @@ -323,8 +323,12 @@
});

$('#quantityInput').on('input', function() {
validateQuantity();
updatePrice();
let value = $(this).val();
if (value.length > 2) {
$(this).val(value.slice(0, 2));
}
validateQuantity();
updatePrice();
});

$('#quantityMinus').on('click', function() {
Expand Down Expand Up @@ -394,53 +398,49 @@ function updatePrice() {
}

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() || $('#noneServingOrType').val();
let flavorOrSize = $('#flavorOrSizeGroup .active').text() || $('#defaultFlavorOrSize').val() || $('#noneFlavorOrSize').val();
let quantity = $('#quantityInput').val();
let price = $('#priceDisplay').val();

if (servingOrType === 'Default' || servingOrType === 'None') servingOrType = '';
if (flavorOrSize === 'Default' || flavorOrSize === 'None') flavorOrSize = '';

$.ajax({
url: 'add_to_order_cart.php',
type: 'POST',
data: {
product_id: productId,
product_type: productType,
product_name: productName,
serving_or_type: servingOrType,
flavor_or_size: flavorOrSize,
quantity: quantity,
price: price
},
success: function(response) {
let data = JSON.parse(response);
if (data.status === 'success') {
fetchCartItems();
calculateSubtotal();
$('#product').modal('hide');
} else {
alert('Failed to add item to order cart');
}
$("#addToOrderCart").prop("disabled", false);
},
error: function() {
alert('An error occurred. Please try again.');
$("#addToOrderCart").prop("disabled", false);
}
});
}
let productId = $('#product').data('product-id');
let productType = $('#product').data('product-type');
let productName = $('#productName').text();
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();

$("#addToOrderCart").on("click", function(event) {
event.preventDefault();
$(this).prop("disabled", true);
addToCart();
});
if (servingOrType === 'Default' || servingOrType === 'None') servingOrType = '';
if (flavorOrSize === 'Default' || flavorOrSize === 'None') flavorOrSize = '';

$.ajax({
url: 'add_to_order_cart.php',
type: 'POST',
data: {
product_id: productId,
product_type: productType,
product_name: productName,
serving_or_type: servingOrType,
flavor_or_size: flavorOrSize,
quantity: quantity,
price: price
},
success: function(response) {
let data = JSON.parse(response);
if (data.status === 'success') {
fetchCartItems();
calculateSubtotal();
$('#product').modal('hide');
} else {
alert('Failed to add item to order cart');
}
},
error: function() {
alert('An error occurred. Please try again.');
}
});
}

$("#addToOrderCart").on("click", function(event) {
event.preventDefault();
addToCart();
});

function fetchCartItems() {
$.ajax({
Expand Down
4 changes: 2 additions & 2 deletions src/javascript/billing.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ $(document).ready(function () {
// Tendered amount validation and change calculation
function enforceTenDigits(event) {
const input = event.target.value;
if (input.length > 21) {
event.target.value = input.slice(0, 21);
if (input.length > 10) {
event.target.value = input.slice(0, 10);
}
}

Expand Down

0 comments on commit f08d447

Please sign in to comment.