snapjay / ngCart

Really simple shopping cart for AngularJS
http://ngcart.snapjay.com
380 stars 236 forks source link

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

Open humbkr opened 9 years ago

humbkr commented 9 years ago

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.

snapjay commented 9 years ago

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 commented 9 years ago

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.

Rex90 commented 8 years ago

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.