Skip to content

Implement Shopping Cart Functionality #4

@nomdal

Description

@nomdal

Overview

Implement a complete shopping cart system for the OctoCAT Supply Chain Management application, including cart state management, cart page UI, and navigation integration.

Features to Implement

1. State Management

  • Create a Cart Context similar to existing AuthContext and ThemeContext
  • Implement cart state structure (product details, quantity, unit price, total price)
  • Add localStorage persistence for cart data across browser sessions

2. Cart Context Provider

  • Add/Remove items functionality
  • Update quantity functionality
  • Automatic calculation of subtotal, discounts, shipping, and grand total
  • Maintain cart item count for navbar badge
  • Clear cart functionality

3. Navigation Enhancement

  • Add shopping cart icon to Navigation.tsx component
  • Display item count badge on cart icon
  • Ensure cart icon styling works with dark/light theme

4. Cart Page Component

  • Create cart table with columns:
    • S. No.
    • Product Image
    • Product Name
    • Unit Price
    • Quantity (with increment/decrement controls)
    • Total
    • Remove button
  • Implement Order Summary section with:
    • Subtotal
    • Discount calculation
    • Shipping costs
    • Grand total
  • Add action buttons: Update Cart, Apply Coupon, Proceed to Checkout

5. Product Integration

  • Add 'Add to Cart' button to Products.tsx component
  • Enhance product modals with cart actions
  • Implement quantity selector for adding products

6. Routing

  • Add /cart route to React Router configuration
  • Update navigation to include cart page link

7. UI/UX Enhancements

  • Add loading states for cart operations
  • Implement success notifications (toast messages)
  • Create empty cart state with call-to-action
  • Ensure responsive design for mobile devices

8. Validation & Error Handling

  • Prevent negative quantities and enforce maximum limits
  • Add product availability checks
  • Validate coupon codes and quantities

9. Styling Consistency

  • Integrate with existing dark/light theme system
  • Use consistent Tailwind classes from existing components
  • Extract reusable components (quantity selectors, price displays)

Acceptance Criteria

  • Users can add products to cart from the product catalog
  • Cart icon in navigation shows current item count
  • Cart page displays all added items with proper formatting
  • Users can modify quantities and remove items from cart
  • Order summary calculates totals correctly including discounts
  • Cart state persists across browser sessions
  • All functionality works in both dark and light themes
  • Responsive design works on mobile and desktop

Technical Requirements

  • Maintain TypeScript patterns and component structure
  • Follow existing code patterns and architecture
  • Ensure compatibility with current build system
  • Add appropriate error handling and validation

Related Files

  • frontend/src/components/Navigation.tsx
  • frontend/src/components/entity/product/Products.tsx
  • frontend/src/context/ (new CartContext)
  • frontend/src/App.tsx (routing)

Priority

Medium - This feature will enhance the user experience and demonstrate complete e-commerce functionality for the demo application.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions