1

I'm trying to remove a product from a cart but i'm getting an {error: "Line item not found"} error and I can't figure out why. Here is my code:

$('.js-item').on('click', function(e) {
    e.preventDefault();
    var id = $(this).data('item-id');
    var csrfToken = $(this).data('csrftoken');

    $.ajax({
        type: "POST",
        dataType: 'json',
        headers: {
            "X-CSRF-Token": csrfToken,
        },
        data: {
            'action': 'commerce/cart/update-cart',
            'lineItems': {
                [id]: {
                    'remove': true
                }
            }
        },
        success: function(data) {
            alert("removed");
        }
    });
});


{% set cart = craft.commerce.carts.cart %}
{% set cartItems = cart.getLineItems() %}
  {% for item in cartItems %}
    <li class="js-item" data-item-id="{{item.snapshot.id}}">{{item.snapshot.title}}</li>
  {% endfor %}
{% endfor %}

Your Answer

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

Browse other questions tagged or ask your own question.