ngCart icon indicating copy to clipboard operation
ngCart copied to clipboard

Impossible to add the same item twice in the cart using ngCart.addItem()

Open humbkr opened this issue 9 years ago • 3 comments

After modifying the addToCart html template to always display the add to cart link, if I display the add to cart link to allow a user to add one item to the cart, ie: <ngcart-addtocart id="{{item.id + productsIds[item.sku]}}" name="{{item.label}}" price="{{item.price}}" quantity="1">Add to cart</ngcart-addtocart> It is impossible for that user to add the same product again to the cart without going to the cart detail view. This seems wrong as the logical behaviour would be to update the quantity of that item in the cart according to the directive's quantity tag, not to do nothing.

This is due to the fact that the function used to update a cart item quantity, item.prototype.setQuantity() is called in ngCart.addItem() with its second parameter "relative" set to false. What is exactly the purpose of this parameter? I don't understand the logic to not let the developer use this parameter in ngCart.addItem().

This works perfectly when I modify the code of ngCart.addItem() to call setQuantity with relative set to true.

humbkr avatar Jan 04 '15 16:01 humbkr

Yes agreed - It does bug me that the 'Add to Cart' button disappears, it would work better if you can change the quantity instead - again like Amazon.

snapjay avatar Jan 04 '15 20:01 snapjay

This has now been added into Master and updated on the demo site. Not quite the same as Amazon when it appends the quantity, but now you can see the quantity and adjust it from the Add to Cart Button.

snapjay avatar Jan 21 '15 22:01 snapjay

I agree, addItem with relative = true should be the default. I made this change in my own code but I would prefer not to mess with the source code of ngCart.

Rex90 avatar Oct 06 '16 10:10 Rex90