Cart Management

⚠️

Deprecation Notice

All Cart v1 and Cart v2 APIs are now deprecated. They remain available but will no longer receive feature updates (critical bug fixes only). These routes will be removed in a future release once all migrations are complete.

It is strongly recommended to migrate to Order-based Checkout. See the Migration Guide (Cart v2 → Order-based Checkout) for a step-by-step transition plan.

Cart Management System

Overview

The cart management system is a core feature of the application that allows users to manage their
purchases. It provides a complete and flexible cart management solution, with the ability to handle
multiple carts simultaneously. This architecture enables a rich user experience while maintaining
clear data separation between different accounts.

Architecture

Multi-Cart per User

graph TD
    U[User] --> A1[Account 1]
    U --> A2[Account 2]
    A1 --> P1[Cart 1]
    A1 --> P2[Cart 2]
    A2 --> P3[Cart 3]
    A2 --> P4[Cart 4]

Multi-cart management is a fundamental aspect of our system. Each user can create and manage
multiple carts simultaneously, each associated with a specific account. This architecture provides
great flexibility in purchase management while maintaining clear data separation between different
accounts. Carts are completely isolated between accounts, ensuring data confidentiality and
integrity.

Data Structure

ComponentDescriptionAccess
General InformationBasic cart datagetCartById
- IDUnique cart identifier
- NameCustom cart name
- StatusCurrent state (DRAFT/VALIDATED/CANCELLED)
- TypeCart type (CART/BUYING_LIST)
- CurrencyPrice currency
- DatesCreation and modification dates
- Total priceCart total amount
Cart LinesProduct detailsgetCartLines
- ProductsProduct information
- QuantitiesOrdered quantities
- Unit pricesPrice per unit
- OffersOffer information
- MetadataAdditional data

The cart data structure is divided into two main components, each accessible through specific
endpoints. This separation enables optimized resource management and better performance when
retrieving data.

Main Features

1. Cart Management

sequenceDiagram
    participant U as User
    participant F as Frontend
    participant A as API
    participant S as Store

    U->>F: Cart action
    F->>A: API request
    A->>S: Store update
    S->>F: UI update
    F->>U: Confirmation

The system provides a complete suite of cart management features. Creating new carts (createCart)
allows users to start new shopping sessions. Retrieving the cart list (fetchCarts) provides an
overview of all active carts. For specific details, getCartById provides general information,
while update operations (updateCartLines, addOrUpdateCartLines) enable fine-grained product
management in the cart.

2. Security and Authentication

Security is a crucial aspect of our system. Every cart operation requires valid authentication,
ensuring that only authorized users can access their data. The system systematically verifies access
rights per account, ensuring complete data isolation between different accounts. Data validation is
performed at each step to maintain system integrity.

3. State Management

stateDiagram-v2
    [*] --> DRAFT
    DRAFT --> VALIDATED
    DRAFT --> CANCELLED
    VALIDATED --> [*]
    CANCELLED --> [*]

The cart lifecycle follows a well-defined state flow. A cart always starts in the DRAFT state,
allowing users to modify it freely. Once finalized, it can be VALIDATED, marking the end of its
modification phase. Alternatively, a cart can be CANCELLED if the user decides to abandon it. This
state management enables precise control over the cart lifecycle.

4. Synchronization

Data synchronization is an essential aspect of our system. The Pinia store is updated in real-time
to reflect changes, providing a smooth user experience. Multi-device synchronization allows users to
access their carts from any device, while session management ensures data consistency. The system
uses intelligent caching to optimize performance and reduce server load.

Key Points

Performance

System performance is optimized at multiple levels. Pagination is implemented for the cart list,
enabling efficient navigation even with a large number of carts. Separate loading of cart lines
reduces initial data transfer. A sophisticated caching system stores frequently used responses,
while API request optimization minimizes latency.

Flexibility

The system is designed to be highly flexible. It supports multiple currencies, allowing users to
work in their preferred currency. Cart types are customizable, adapting to different purchasing
needs. The system offers advanced filtering and sorting options, while detailed error handling
facilitates debugging and continuous improvement.

Integration

Integration with other systems is a priority. The system seamlessly integrates with our
authentication system, ensuring robust security. Pinia store synchronization is optimized for
performance, while the notification system keeps users informed of important changes. Error handling
is unified across the application, providing a consistent experience.

Best Practices

  1. Data Retrieval Data retrieval should be optimized for performance. Use getCartById for
    general information and getCartLines only when product details are necessary. This approach
    reduces server load and improves response times.

  2. Error Handling Error handling is crucial for a smooth user experience. All 401 (unauthorized)
    error cases must be handled appropriately, with redirection to the login page if necessary. Data
    validation must be performed at each step, and error messages must be clear and informative.

  3. Performance Performance optimization is essential. Use pagination for cart lists, cache
    frequently used data, and avoid unnecessary requests. These practices help maintain fast response
    times even with a large number of users.

  4. Security Security is an absolute priority. Systematically verify access rights, validate all
    client-side data, and protect sensitive routes. These measures ensure the integrity and
    confidentiality of user data.

Conclusion

The cart management system provides a complete and flexible solution for managing user purchases. It
enables multi-cart management, clear data separation by account, and a performance-optimized
architecture. This documentation provides an overview of the system, but for more details on each
specific feature, please refer to the detailed documentation in the functions folder.


Did this page help you?