Advanced Flows: Cart Lifecycle
The Archibald Cart module handles complex lifecycle transitions, most notably the transition from an anonymous guest cart to a registered user cart.
Anonymous to Registered Merge Flow
When a user adds items to their cart as a guest and subsequently logs in, the framework manages the merging of these carts to ensure no data is lost.
Key Considerations
- Identifier Transition: The hook automatically switches from using the
guid(anonymous) to thecode(registered) identifier after a successful merge. - Event Propagation: The
CartClientwill emit a'cart'event with the merged state, allowing UI components to refresh automatically. - Persistence: The
useCartIdhook updates the underlying cookie/storage to ensure the registered cart persists across page reloads.