feat: add detailed logging to add to cart functionality for debugging
Added comprehensive console logging to track: - Cart eligibility checks - API request URL and payload - Response status and data - Error details This will help identify why items aren't being added to cart. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -354,28 +354,50 @@ document.addEventListener('alpine:init', () => {
|
|||||||
|
|
||||||
// Add to cart
|
// Add to cart
|
||||||
async addToCart() {
|
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;
|
this.addingToCart = true;
|
||||||
|
|
||||||
try {
|
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(
|
console.log('[SHOP] Adding to cart:', {
|
||||||
`/api/v1/shop/cart/${this.sessionId}/items`,
|
url,
|
||||||
{
|
sessionId: this.sessionId,
|
||||||
|
productId: this.productId,
|
||||||
|
quantity: this.quantity,
|
||||||
|
payload
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(payload)
|
||||||
product_id: parseInt(this.productId),
|
});
|
||||||
quantity: this.quantity
|
|
||||||
})
|
console.log('[SHOP] Add to cart response:', {
|
||||||
}
|
status: response.status,
|
||||||
);
|
ok: response.ok
|
||||||
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
const result = await response.json();
|
||||||
|
console.log('[SHOP] Add to cart success:', result);
|
||||||
|
|
||||||
this.cartCount += this.quantity;
|
this.cartCount += this.quantity;
|
||||||
this.showToast(
|
this.showToast(
|
||||||
`${this.quantity} item(s) added to cart!`,
|
`${this.quantity} item(s) added to cart!`,
|
||||||
@@ -386,10 +408,11 @@ document.addEventListener('alpine:init', () => {
|
|||||||
this.quantity = this.product?.min_quantity || 1;
|
this.quantity = this.product?.min_quantity || 1;
|
||||||
} else {
|
} else {
|
||||||
const error = await response.json();
|
const error = await response.json();
|
||||||
|
console.error('[SHOP] Add to cart error response:', error);
|
||||||
throw new Error(error.detail || 'Failed to add to cart');
|
throw new Error(error.detail || 'Failed to add to cart');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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');
|
this.showToast(error.message || 'Failed to add to cart', 'error');
|
||||||
} finally {
|
} finally {
|
||||||
this.addingToCart = false;
|
this.addingToCart = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user