Skip to content

Instantly share code, notes, and snippets.

@gterrill
Last active August 29, 2015 13:56
Show Gist options
  • Save gterrill/8941724 to your computer and use it in GitHub Desktop.
Save gterrill/8941724 to your computer and use it in GitHub Desktop.
Ajax Add to Cart with bta.BookingForm
function addToCart(e){
if (typeof e !== 'undefined') e.preventDefault();
// make sure BTA has loaded
if ($('#add-to-cart').hasClass('bta-load-enable')) {
alert('Please wait while we look up class availability');
return false;
}
var form = $(this).parents('form'),
data = [],
btaForm = form.data('bta.bookingForm');
if (!btaForm.isValid()) {
return false;
}
data.push(["id", form.find('[name="id"]').val()].join('='));
data.push(["quantity", form.find('[name="quantity"]').val() || 1].join('='));
btaForm.pushProperties(data);
$.ajax({
type: 'POST',
url: '/cart/add.js',
async: false,
cache: false,
data: data.join('&'),
dataType: 'json',
error: addToCartFail,
success: addToCartSuccess,
cache: false
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment