Skip to content

Instantly share code, notes, and snippets.

@mattrayner
Last active July 30, 2019 09:56
Show Gist options
  • Save mattrayner/6e0ddd32670b18d7cbe0ad4eef2a45e5 to your computer and use it in GitHub Desktop.
Save mattrayner/6e0ddd32670b18d7cbe0ad4eef2a45e5 to your computer and use it in GitHub Desktop.
Dinotropolis Cart Issues
/*
Below are updated functions which fix the issues noted in issues.js below.
I have tested these on my local machine and was able to make a booking successfully with the updated functions.
*/
function addQuantity(){
var quantity = parseInt($('#productSelectQuantity').val());
quantity++;
if(quantity < 0) // Handle quntity lower than 0
quantity = 1
if(quantity > 0) // If we have some items, enable add to cart
$("#addToCartItem").removeAttr("disabled");
$('#productSelectQuantity').val(quantity); // Update the quantity shown
}
function lessQuantity(){
var quantity = parseInt($('#productSelectQuantity').val());
quantity--;
if(quantity < 0) // Stop quantity from going below 0
quantity = 0;
if(quantity <= 0) // Disable cart if we have 0 or fewer items to add
$("#addToCartItem").attr("disabled","disabled");
$('#productSelectQuantity').val(quantity); // Update the quantity shown
}
/*
Below are the addQuantity and lessQuantity JavaScript functions taken from dinotropolis.co.uk (https://dinotropolis.secure.force.com specifically) on 2019-07-29 at 14:02:33
annotated to show the issues preventing people from making an online booking.
*/
function addQuantity(){
var quantity = parseInt($('#productSelectQuantity').val());
if(quantity === 0){ // This check should look for larger than 0
$("#addToCartItem").removeAttr("disabled");
}
if(quantity < -2) // This if statement seems random and changes between refreshes, some time it's -1, sometimes -2
$('#productSelectQuantity').val(quantity + 1); // <------ The cause of your problem is you only update the value here
}
function lessQuantity(){
var quantity = parseInt($('#productSelectQuantity').val());
if(quantity>0){ // This is covered by the rest of your statements so not needed
if(quantity === 1) // This check should be for less than 1
$("#addToCartItem").attr("disabled","disabled");
if(quantity > 1) // This check should be > 0, not > 1 - this stops you from going below 1
$('#productSelectQuantity').val(quantity - 1); // <----- You only update the number is it is 2 or higher, meaning you can never go down to 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment