Open Platonn opened 5 years ago
1.1. If there is no anonymous cart, we just load user's current
cart. (In OCC, there is no 'load current cart' API, so we load all user's carts, and return the first one. )
1.2. If there is anonymous cart, then we load user's current
cart and do the merge.
current
cart, we merge the anonymous cart into the current
cart.cartId
, then we use current
(e.g. we don't know the cartId
when user login) . If there is cartId
, we use cartId
.cartId
is cart's code; for anonymous user, cartId
is guid
cartId
or by current
? If by cartId
, then cart must exist in backend; if by current
, it doesn't matter cart exist or not. If not exist, you just get empty value.About 'current' vs 'anonymous':
For occ calls in general in Spartacus, when a userId is required in the occ call url, the app uses the special id 'current', which tells the server to obtain the userId from the auth token provided in the request.
When no user is authenticated, the user id 'anonymous' is used in the url of occ calls that require a userId in the url.
There are many nuances in the cart's mechanism. It would be good to document all those. Then we can think of optimizing current architecture of OCC API and Sparatacus code. We should also cover all those documented nuances with e2e tests.
For example:
'anonymous'
for unsigned users and real userId for signed ones'current'
(orcart.code
? I'm not sure) for signed users andcart.guid
for unsigned usersIt's an open discussion. So please share thoughts in comments.