Last active
December 16, 2015 21:20
-
-
Save gterrill/5499051 to your computer and use it in GitHub Desktop.
Ajax add to cart capturing booking line item properties
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(); | |
if (!$('form[action="/cart/add"]').valid()) { | |
return; | |
} | |
var form = $(this).parents('form'), | |
data = []; | |
data.push(["id", form.find('[name="id"]').val()].join('=')); | |
data.push(["quantity", form.find('[name="quantity"]').val() || 1].join('=')); | |
if (form.find('[name="properties[booking-start]"]').length > 0) { | |
data.push(["properties[booking-start]", bta.toLocalIsoString(form.find('[name="properties[booking-start]"]').datepicker('getDate'), false)].join('=')); | |
data.push(["properties[booking-finish]", bta.toLocalIsoString(form.find('[name="properties[booking-finish]"]').datepicker('getDate'), false)].join('=')); | |
} | |
$.ajax({ | |
type: 'POST', | |
url: '/cart/add.js', | |
async: false, | |
cache: false, | |
data: data.join('&'), | |
dataType: 'json', | |
error: addToCartFail, | |
success: addToCartSuccess | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment