Overview
The Mis Compras shopping cart system allows you to collect multiple products before completing your purchase. Your cart is stored locally in your browser, so items persist even if you navigate away or close the tab.Adding Items to Cart
From Product Pages
On any product detail page (producto.html), you’ll find action buttons to add items to your cart.
Quick Add from Category Pages
You can also add products directly from category listing pages using the “Agregar al carrito” button on product cards.Items added to your cart include: product ID, name, price, image URL, quantity, and calculated subtotal.
Viewing Your Cart
Accessing the Cart Page
Navigate to your shopping cart by clicking “Carrito” in the main navigation menu, which takes you tocarrito de compras.html.
Cart Display
Your cart page shows:Cart Item Information
- Product Image - Visual reference with error handling
- Product Name - Full product title
- Unit Price - Individual item price (
$XX.XX) - Quantity - Number of items added
- Subtotal - Calculated as
quantity × price - Remove Button - × icon to delete item
Cart Layout
Cart Storage System
LocalStorage Implementation
The cart uses browser localStorage for persistence with the keymiTienda_carrito_v1:
Cart Data Management
The cart system (carrito.js) provides a global API:
Managing Cart Items
Updating Quantities
When you add the same product multiple times, the cart automatically:- Detects duplicate - Searches for existing item by ID
- Increments quantity - Adds 1 to the existing quantity
- Recalculates subtotal - Updates
subtotal = quantity × price - Saves changes - Persists to localStorage
Currently, quantities automatically increment by 1 with each “Add to Cart” action. To adjust quantities, you need to remove and re-add items.
Removing Items
Cart Totals
Price Calculation
The cart automatically calculates your total:- Item Subtotals - Each item shows
quantity × unit price - Cart Total - Sum of all subtotals displayed at bottom
- Formatted Display - All prices shown as
$X,XXX.XX
Total Display
The cart footer shows:Empty Cart State
When your cart is empty, you’ll see:$0.00
The cart page automatically renders on page load via the
renderCart() function in carrito.js:143-175.Cart Persistence
Session Continuity
Your cart data persists across:- Page Navigation - Items remain when browsing the site
- Browser Refresh - Cart survives page reloads
- Tab Closure - Items saved until browser data is cleared
Data Cleanup
Your cart is automatically cleared when:- You complete a successful checkout
- You manually clear browser localStorage
- You call
window.carrito.clear()
Cart Limitations
Current Constraints
Quantity Management
- No manual quantity input field
- Must add items multiple times to increase quantity
- To reduce quantity, remove item and re-add desired number of times
Stock Validation
- No real-time stock checking
- Inventory validation happens at checkout
- May see stock errors during final purchase
Best Practices
Review Before Checkout
Always review your cart items, quantities, and total before proceeding to checkout
Technical Details
Error Handling
The cart system includes robust error handling:Price Parsing
Prices are normalized to handle various formats:Next Steps
Checkout Process
Complete your purchase
Order Tracking
Track your orders after purchase
Related Resources
- See
carrito.js:1-196for complete cart implementation - View
carrito de compras.htmlfor cart page structure - Check
carrito diseño.cssfor cart styling