Skip to content

How to update cart with if clause? #29

@Brecht272727

Description

@Brecht272727

Hi,

I am looking for a solution where i can update the cart with p.e. product.id and product.sizeId
But the code below is not working.

var winkelwagen = cartLS.list();
var id = 2;
var size = 4;
var new_qty = 100;

for (var i = 0; i < winkelwagen.length; i++) {
    if (winkelwagen[i].id === id && winkelwagen[i].sizeId === size) {
        winkelwagen[i].quantity = new_qty;
        break;
    }
}

// Update the cart
cartLS.update(winkelwagen);

The problem is that i have p.e. 2 products with the same ID but with different sizeId. So both were updated what is not correct of course.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions