Skip to content

Instantly share code, notes, and snippets.

@expl0ratory
Last active November 20, 2019 19:41
Show Gist options
  • Save expl0ratory/3b5670fa46481681ed28 to your computer and use it in GitHub Desktop.
Save expl0ratory/3b5670fa46481681ed28 to your computer and use it in GitHub Desktop.
Cratejoy AJAXable Storefront Endpoints
$.ajax({
type: 'POST',
url: '/cart/add',
data: {
quantity: 1,
term_cycles: cycle_count, // ecom products have no term_cycles
// if it's a pre-pay sub, the # of prepaid cycles is this value, 1 = month-to-month
// 3 = quarterly prepay, etc
product_id: item.id // product_instance_id
},
success: function(data) {
console.log('Cart item id is ' + data.id);
}
});
$.ajax({
'url': '/cart/clear',
'method': 'POST',
'success': function(data) {
console.log('Cleared cart');
},
'async': false
});
$.ajax({
type: 'POST',
url: '/checkout/remove/' + data.id, // cart item id from add
success: function(data) {
// data.id is cart item id as a confirmation
}
});
@lkbm
Copy link

lkbm commented Nov 20, 2019

Update on the "Clearing a cart" route:

$.post("/cart/clear"); // Removes products, but not coupons.
$.post("/cart/clear", data={"clear_coupons": true}); // Removes products and coupons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment