Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change input field of tendered amount from 21 to 10,quantity input ma… #62

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading