Last active
November 20, 2019 19:41
-
-
Save expl0ratory/3b5670fa46481681ed28 to your computer and use it in GitHub Desktop.
Cratejoy AJAXable Storefront Endpoints
This file contains 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
$.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); | |
} | |
}); |
This file contains 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
$.ajax({ | |
'url': '/cart/clear', | |
'method': 'POST', | |
'success': function(data) { | |
console.log('Cleared cart'); | |
}, | |
'async': false | |
}); |
This file contains 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
$.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 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update on the "Clearing a cart" route: