Last active
August 29, 2015 13:56
-
-
Save gterrill/8941724 to your computer and use it in GitHub Desktop.
Ajax Add to Cart with bta.BookingForm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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