Created
August 27, 2013 13:11
-
-
Save resistorsoftware/6353325 to your computer and use it in GitHub Desktop.
Some simple Ajax cart
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
<h1>Product.Liquid crap goes here... lalalalala whatever... </h1> | |
<script type="text/javascript"> | |
// I hacked the Ajax API to add line item properties for a product too. | |
function addToCart() { | |
var item = DaveWuzHere.utils.popQueue(); | |
if(item) { | |
if(item.properties) { | |
Shopify.api.addItemWithProperties(item.id, item.quantity, item.properties, addToCart); | |
} else { | |
Shopify.api.addItem(item.id, item.quantity, addToCart); | |
} | |
} else { | |
// I jump to the cart, but you could do a jig here and make a nice report in a popup or whatever. | |
document.location.href="/cart" | |
} | |
} | |
jQuery(document).ready(function(){ | |
$("#add_to_cart").on('click', function(e){ | |
e.preventDefault(); | |
// go through a list of checked of radio elements representing different products | |
var valid = $("input:checkbox[name=main_variant]:checked"); | |
$.each(valid, function(idx,item){ | |
var id = $(this).data("id"); | |
var properties = []; | |
properties.push("properties[id]="+$(extra).val()); | |
properties.push("properties[title]="+$(extra).data("title")); | |
DaveWuzHere.utils.pushQueue({id: id, quantity: 1, properties: properties}); | |
}); | |
addToCart(); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment