2. Overview of the shopping cart feature + technical requirements
Notes
The shopping cart feature has some complex requirements both from the UI and the data/backend perspective, and these are explained in this article:
Shopping Cart UI
We can view and modify the shopping cart data from multiple pages/widgets:
Shopping Cart Backend
In addition, we need to be able to add items to the shopping cart either as a guest user, or as a signed-in user.
When signed-in, users will have a unique identifier (uid
) that can be used to read the shopping cart data (each user has his/her own shopping cart).
But how can we store shopping data for guest users, who don't have a uid
.
Two solutions are possible.
Anonymous user
The main idea is to sign in anonymously as soon as the app starts for the first time.
This will generate a uid
that can be used to save the shopping cart data on the backend.
This solution is represented here:
One drawback of this approach is that if the same user installs the app on a new device, a different uid
will be generated, and this makes it hard to reconcile the shopping cart data with the previous account after sign in.
Guest user with local storage
This solution works by keeping a local shopping cart that is used by guest users, along with a remote shopping cart that is used by signed-in users:
This overcomes some of the problems with the previous approach, but requires some additional logic to move the local shopping cart data to the remote shopping cart when the user signs in.
3 comments