1

I am trying to change/set a customers shippingAddress via axios

It does work e.g. for setting the shippingMethod or the quantity for a product. However if i want to set a new shippingAddress the axios post fails with a 500 status

This is my axios post request:

updateShipping() {
        const options = {
            method: 'POST',
            headers: {
                'content-type': 'application/x-www-form-urlencoded',
                'X-CSRF-Token': window.Craft.csrfToken,
            },
            data: qs.stringify({
                shippingMethodHandle: 'standardShipping', //works
                shippingSameAsBilling: false, // wont work
                shippingAddressId: 'new', // wont work, also tried an existing
                shippingAddress: {
                   firstName: 'test',
                   ...
                },
            }),
            url: '/actions/commerce/cart/update-cart',
        };
        axios(options)
            .then(response => {...})
            .catch(error => {...});
    },
1

Stumbled over the old questions, this is how it works:

updateShipping() {
        const options = {
            method: 'post',
            url: '/actions/commerce/cart/update-cart',
            headers: {
                'X-CSRF-Token': window.Craft.csrfToken,
            },
            data: qs.stringify({
                shippingMethodHandle: 'standardShipping',
                shippingSameAsBilling: 0,
                shippingAddressId: 123, // remove if it doesn't exists or is new
                shippingAddress: {
                   id: '', // only needed if address is new
                   firstName: 'test',
                   ...
                },
            }),
        };
        axios(options)
            .then(response => {...})
            .catch(error => {...});
    },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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