notrab / react-use-cart

React hook library for managing cart state
http://npm.im/react-use-cart
Apache License 2.0
367 stars 48 forks source link

Support multiple cart item types #59

Closed notrab closed 3 years ago

notrab commented 3 years ago

Similar to CartQL, it would be helpful to group cart items based on their type.

For example, SKU, TAX, SHIPPING would permit new subTotal, taxTotal, grandTotal, and shippingTotal values.

luis-cruzt commented 3 years ago

This would be great.

notrab commented 3 years ago

@luis-cruzt can you tell me a bit more about your use case?

I'm thinking addItem takes a type as mentioned above that is either SKU, TAX, or SHIPPING, and updates the correct totals.

SKU would be the default. I think this is a fairly basic implementation that stays very agnostic to the implementation.

notrab commented 3 years ago

Thinking about this some more, TAX will most likely need to be added to the Item type, as items can have their own tax amounts.

Shipping would also be a new type that doesn't have a quantity, but you can add multiple shipping items with different IDs.

luis-cruzt commented 3 years ago

Actually the way you are describing it's correct, as for some items sometimes they have their own tax amount, I think is a nice approach.

In my use case is very basic, because my client already included the tax amount per item (don't know why).

luis-cruzt commented 3 years ago

Why is this being closed?