fix: resolve cart functionality issues with product name and frontend integration
Fixed two critical issues preventing cart from working:
1. Product Name Attribute Error:
- Product model doesn't have 'name' attribute directly
- Product name comes from marketplace_product.title relationship
- Updated all references in cart_service.py:
* get_cart() - product display in cart
* add_to_cart() - logging and exception messages
* update_cart_item() - exception messages
- Also updated image_url to use marketplace_product.image_link
2. Products Page Not Calling API:
- products.html had stub addToCart() with TODO comment
- Implemented actual API call:
* POST to /api/v1/shop/cart/{sessionId}/items
* Sends product_id and quantity
* Updates cartCount on success
* Shows error toast on failure
* Proper error handling with try/catch
Testing Results:
- API endpoint now works correctly (tested with curl)
- Cart items are properly saved to database
- Product names display correctly from marketplace_product relationship
- Frontend can successfully add items to cart
Related Models:
- Product has relationship to MarketplaceProduct
- Product.marketplace_product.title contains the product name
- Product.marketplace_product.image_link contains the image URL
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -81,11 +81,11 @@ class CartService:
|
||||
|
||||
items.append({
|
||||
"product_id": product.id,
|
||||
"product_name": product.name,
|
||||
"product_name": product.marketplace_product.title,
|
||||
"quantity": cart_item.quantity,
|
||||
"price": cart_item.price_at_add,
|
||||
"line_total": line_total,
|
||||
"image_url": product.image_link if hasattr(product, 'image_link') else None,
|
||||
"image_url": product.marketplace_product.image_link if product.marketplace_product else None,
|
||||
})
|
||||
|
||||
subtotal += line_total
|
||||
@@ -157,10 +157,10 @@ class CartService:
|
||||
raise ProductNotFoundException(product_id=product_id, vendor_id=vendor_id)
|
||||
|
||||
logger.info(
|
||||
f"[CART_SERVICE] Product found: {product.name}",
|
||||
f"[CART_SERVICE] Product found: {product.marketplace_product.title}",
|
||||
extra={
|
||||
"product_id": product_id,
|
||||
"product_name": product.name,
|
||||
"product_name": product.marketplace_product.title,
|
||||
"available_inventory": product.available_inventory
|
||||
}
|
||||
)
|
||||
@@ -195,7 +195,7 @@ class CartService:
|
||||
)
|
||||
raise InsufficientInventoryForCartException(
|
||||
product_id=product_id,
|
||||
product_name=product.name,
|
||||
product_name=product.marketplace_product.title,
|
||||
requested=new_quantity,
|
||||
available=product.available_inventory
|
||||
)
|
||||
@@ -230,7 +230,7 @@ class CartService:
|
||||
)
|
||||
raise InsufficientInventoryForCartException(
|
||||
product_id=product_id,
|
||||
product_name=product.name,
|
||||
product_name=product.marketplace_product.title,
|
||||
requested=quantity,
|
||||
available=product.available_inventory
|
||||
)
|
||||
@@ -319,7 +319,7 @@ class CartService:
|
||||
if product.available_inventory < quantity:
|
||||
raise InsufficientInventoryForCartException(
|
||||
product_id=product_id,
|
||||
product_name=product.name,
|
||||
product_name=product.marketplace_product.title,
|
||||
requested=quantity,
|
||||
available=product.available_inventory
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user