diff --git a/app/services/cart_service.py b/app/services/cart_service.py index 18bef52e..d566b244 100644 --- a/app/services/cart_service.py +++ b/app/services/cart_service.py @@ -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 ) diff --git a/app/templates/shop/products.html b/app/templates/shop/products.html index dfd44ae9..43f3a6cb 100644 --- a/app/templates/shop/products.html +++ b/app/templates/shop/products.html @@ -201,10 +201,38 @@ document.addEventListener('alpine:init', () => { this.loadProducts(); }, - addToCart(product) { + async addToCart(product) { console.log('[SHOP] Adding to cart:', product); - this.showToast(`${product.marketplace_product.title} added to cart`, 'success'); - // TODO: Implement actual cart functionality + + try { + const url = `/api/v1/shop/cart/${this.sessionId}/items`; + const payload = { + product_id: product.id, + quantity: 1 + }; + + const response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(payload) + }); + + if (response.ok) { + const result = await response.json(); + console.log('[SHOP] Add to cart success:', result); + this.cartCount += 1; + this.showToast(`${product.marketplace_product.title} added to cart`, 'success'); + } else { + const error = await response.json(); + console.error('[SHOP] Add to cart error:', error); + this.showToast(error.message || 'Failed to add to cart', 'error'); + } + } catch (error) { + console.error('[SHOP] Add to cart exception:', error); + this.showToast('Failed to add to cart', 'error'); + } } })); });