2

I am attempting to delete a commerce line item with ajax request but nothing ever deletes. Am i doing something wrong? Vue function below:

removeLine(id) {

            axios.post('', {
                    [this.csrfName]: this.csrfToken,
                    action: 'commerce/cart/update-cart',
                    lineItems: {[id]: {'remove': true}}
            },
            {
                headers: {
                    'X-CSRF-Token': this.csrfToken
                },
            }).then(function (response) {

            }).catch(function (error) {
                // handle error
                console.log(error);
            }).finally(function () {
                // always executed
            });
        }

1 Answer 1

3

Issue resolved. Having checked with Yii debug bar i could see that there was no $_post data with the request. It seems axios sends the data as JSON and not usual post data. Switching to vue-resource enabled me to post the data for craft to use, new code:

this.$http.post('', {
    [this.csrfName]: this.csrfToken,
    action: 'commerce/cart/update-cart',
    lineItems: {[id]: {'remove': 1}}
}, {
    emulateJSON: true,
    headers: {
        'X-CSRF-Token': this.csrfToken
    }
})

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.