I developed the Cart Management module for an existing eCommerce product, which allows cart operations to be accessed seamlessly across the portal for both logged-in and logged-out users. This module uses a Helper class to ensure consistent and efficient cart management.
- The
AuthControlleris responsible for handling user authentication. It includes logic to transfer the logged-out user's cart into the logged-in user's cart when the user logs in or registers. This ensures that any items the user added to their cart while logged out are preserved, except for items already present in the logged-in user's cart.
- The
CartControllerserves as the API endpoint handler for cart operations. When a user adds or deletes items from their cart, the relevant methods inside this controller are called. These methods utilize theCartHelperclass to perform various cart operations. The usage ofCartHelpermethods will be detailed in the next section.
- The
TransferGuestCartToLoggedInUserCartclass contains the logic to transfer the logged-out user's cart into the logged-in user's cart. By setting the logged-out user cart ID and the logged-in user cart ID, any transformation can occur using this file. This service class can be called from other classes by setting the relevant data members using setter methods.
- The
CartHelperclass is the most crucial among the four files. It contains all the business logic related to cart management. Key methods include:get()- Retrieves cart data. It first attempts to get the data from the cache. If the cache is empty, it fetches the data from the database and sets it in the cache for improved performance in subsequent requests.put()- Adds, updates, or deletes data in the cart. This operation affects both the Redis cache and the PostgreSQL database to ensure data consistency and high performance.
The rest methods are used to do several operations.
For support, feel free to email on ronaksolanki1310@gmail.com