Please help. How can I maintain my Cart item’s quantities without using the database?
Objective:
I have a data type of Products, and 2 RGs on a page. The first RG acts as a catalogue showing all products by fetching from the database, and has a state called SelectedProducts (list of Products). The second RG acts as a cart, fetching from a state SelectedProducts.
To minimize Workload Units, I’m avoiding creating a Cart datatype and instead relying on state. Each cart item has a quantity counter, but quantity isn’t part of the Product’s data type, so I need to track it client-side until they proceed to checkout.
All I want is to create a client-side cart with individual quantities. Users can add and remove products from the cart, and modify their quantities.
My Problem:
Initially, I had a Quantity (number) state on the cell within the Cart RG, but this leads to a bug when deleting items from the Cart because it seems Bubble persists the Quantity state and tracks it by cell index (not object).
For instance, if I have three items in the cart, with quantities 1, 2, and 3, respectively, and I delete the second item (with quantity 2), then the third item (with quantity 3) has its index changed and inherits the now-deleted item’s quantity (quantity 2).
Moreover, adding a new third item to the cart will inherit the quantity from the position it’s added to (in this case, quantity 3).
What I’ve Tried:
I’ve tried so many workarounds including adding a Quantities (number list) state to the Catalogue RG (with the intent of relating it to the SelectedProducts state by index), but apparently states don’t allow for duplicate values (which is ridiculous because it should be a list, not a set).
Another approach I was about to try was to change the Quantities state to a single comma-delimited string. But this would lead to so much complexity when tracking and deleting quantities (still a viable option though).