Skip to content

[Bug] Cart data is lost after page refresh #2216

Description

@Thisisaindia

Bug Description

When a user adds products to the shopping cart and refreshes the page, all cart items are lost and the cart becomes empty. This negatively impacts the shopping experience because users expect their selected items to remain available until they intentionally remove them.

Steps to Reproduce

  1. Open the website.
  2. Navigate to the Shop page.
  3. Add one or more products to the cart.
  4. Open the Cart page and verify the items are present.
  5. Refresh the page or reopen the website.

Current Behavior

The shopping cart is cleared after page refresh, and all previously added items disappear.

Expected Behavior

Cart data should persist across page reloads. Products added to the cart should remain available after refreshing the page or reopening the browser tab.

Possible Cause

The cart state is currently maintained only in memory and is not being stored in browser storage.

Proposed Solution

  • Store cart data in localStorage whenever items are added, removed, or updated.
  • Load saved cart data from localStorage when the application initializes.
  • Validate stored data before rendering the cart.
  • Ensure cart totals and quantities are restored correctly.

Acceptance Criteria

  • Cart items remain available after page refresh.
  • Cart data persists across browser sessions.
  • Quantity updates are preserved.
  • Cart totals are calculated correctly after restoration.
  • No console errors occur when localStorage is empty or contains invalid data.

Suggested Labels

bug, javascript, enhancement, gssoc26

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions