Skip to content

Latest commit

 

History

History
93 lines (84 loc) · 2.17 KB

File metadata and controls

93 lines (84 loc) · 2.17 KB

Table of Contents

Back to Main Project README

1. Shopping Cart

Purpose

A shopping cart temporarily stores selected items before purchase.

Basic Functions

  • Add items to Cart.
    • If the user is not logged in, save items to the browser cache.
    • If the user logs in, merge cached items with server-side user data.
    • If the user logs out, sync cart items across all platforms (browser, mobile, etc.).
  • Display cart items
  • Checkout selected items.

Cache Data Storage

Cookie or LocalStorage Storage:

  • Cookie: for small data (< 4KB).
  • LocalStorage: for larger data.

Data Structure:

  • Cart (list)
    • Item
      • sku_id (product ID)
      • quantity
      • timestamp (added time)
      • selected (true/false)

Example:

{
    "cart":[
        {
            "sku_id": 123,
            "quantity": 2,
            "selected": true,
            "timestamp": 1578772233
        }
    ]
}

Core Data Storage

MYSQL or Other SQL Databases

Store persistent cart data in a database table.

Data Structure:

  • Cart (table)
    • id
    • user_id
    • sku_id
    • quantity
    • selected
    • timestamp

Redis or Other NoSQL Databases (Optimal)

Use Redis to store temporary cart data per user.

Data Structure:

  • KEY (user id)
  • VALUE (list)
    • Item
      • skuId (product ID)
      • quantity
      • timestamp
      • selected

Example:

{
    "KEY": 567,
    "VALUE":[
        {
          "skuId": 123,
          "quantity": 2,
          "selected": true,
          "timestamp": 1578772233
        }
    ]
}