I am using Store 2 as my e-commerce module, with the AJAX Form plugin to submit products to the cart.

My question is: Is there a way to detect if the item was added successfully and update the CSRF token?

I thought the below would work, but unfortunately not:

$(document).on('click', '.add-basket', function() {
        success: updateCart,
        dataType: 'json'

function updateCart(data, statusText, xhr) {        

    if (data.success) {                                                 

        var url = 'http://www.domain.net/site/embed-mini-basket';

        $('#masthead-mini-basket').load(url, function() {  

    } else {




1 Answer 1


I'm currently not using Store for one of our projects. So I don't know the exact callback you're getting from the ajax call.

But you could store the token and the items in the cart in javascript variables. This makes it possible to compare them with possible new data. It's a bit of a workaround, but it could work...

You could do something like this in the updateCart function:

if(typeof data.csrf_token !== 'undefined' && typeof data.count !== 'undefined'){

    // checking if all data in callback

    if(data.csrf_token != current_csrf_token){
        // new token > change token in html

    if(data.count != current_count){
        // changed shopping cart count > pretty sure there was an update?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.