I have a collection of ShoppingCart; a new ShoppingCart item will be created when user click on “Add to cart”. When users go to ShoppingCart screen, they see duplicated items in ShoppingCart if they added the same product twice or more.
I am assuming you have a 1: many relationship between Cart & Cart Items.
If this is the case, when you add an item to cart, the number of items count starts adding up. This filter needs to be at “Add to Cart” button checking if the count of items (=the name of the item you’re adding to the cart) = 0, then proceed.
this will avoid addition of duplicate items the cart.