diff --git a/app/templates/shop/product.html b/app/templates/shop/product.html
index b40625c5..09f5bd40 100644
--- a/app/templates/shop/product.html
+++ b/app/templates/shop/product.html
@@ -354,28 +354,50 @@ document.addEventListener('alpine:init', () => {
// Add to cart
async addToCart() {
- if (!this.canAddToCart) return;
+ if (!this.canAddToCart) {
+ console.warn('[SHOP] Cannot add to cart:', {
+ canAddToCart: this.canAddToCart,
+ isActive: this.product?.is_active,
+ inventory: this.product?.available_inventory,
+ quantity: this.quantity
+ });
+ return;
+ }
this.addingToCart = true;
try {
- console.log('[SHOP] Adding to cart:', { productId: this.productId, quantity: this.quantity });
+ const url = `/api/v1/shop/cart/${this.sessionId}/items`;
+ const payload = {
+ product_id: parseInt(this.productId),
+ quantity: this.quantity
+ };
- const response = await fetch(
- `/api/v1/shop/cart/${this.sessionId}/items`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- product_id: parseInt(this.productId),
- quantity: this.quantity
- })
- }
- );
+ console.log('[SHOP] Adding to cart:', {
+ url,
+ sessionId: this.sessionId,
+ productId: this.productId,
+ quantity: this.quantity,
+ payload
+ });
+
+ const response = await fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(payload)
+ });
+
+ console.log('[SHOP] Add to cart response:', {
+ status: response.status,
+ ok: response.ok
+ });
if (response.ok) {
+ const result = await response.json();
+ console.log('[SHOP] Add to cart success:', result);
+
this.cartCount += this.quantity;
this.showToast(
`${this.quantity} item(s) added to cart!`,
@@ -386,10 +408,11 @@ document.addEventListener('alpine:init', () => {
this.quantity = this.product?.min_quantity || 1;
} else {
const error = await response.json();
+ console.error('[SHOP] Add to cart error response:', error);
throw new Error(error.detail || 'Failed to add to cart');
}
} catch (error) {
- console.error('[SHOP] Add to cart error:', error);
+ console.error('[SHOP] Add to cart exception:', error);
this.showToast(error.message || 'Failed to add to cart', 'error');
} finally {
this.addingToCart = false;