fix: properly call parent init in cart and product components
Issue: - sessionId was undefined when cart/product pages loaded - Parent shopLayoutData init() was being overridden, not called - Session ID setup in parent wasn't running Solution: - Store reference to baseData before spreading - Explicitly call baseData.init() in child component init - This ensures sessionId is initialized before cart/product logic runs - Add session ID logging for debugging Now the session ID is properly initialized and cart functionality works. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -169,38 +169,47 @@
|
||||
{% block extra_scripts %}
|
||||
<script>
|
||||
document.addEventListener('alpine:init', () => {
|
||||
Alpine.data('shoppingCart', () => ({
|
||||
...shopLayoutData(),
|
||||
Alpine.data('shoppingCart', () => {
|
||||
const baseData = shopLayoutData();
|
||||
|
||||
items: [],
|
||||
loading: false,
|
||||
updating: false,
|
||||
return {
|
||||
...baseData,
|
||||
|
||||
// Computed properties
|
||||
get totalItems() {
|
||||
return this.items.reduce((sum, item) => sum + item.quantity, 0);
|
||||
},
|
||||
items: [],
|
||||
loading: false,
|
||||
updating: false,
|
||||
|
||||
get subtotal() {
|
||||
return this.items.reduce((sum, item) =>
|
||||
sum + (parseFloat(item.price) * item.quantity), 0
|
||||
);
|
||||
},
|
||||
// Computed properties
|
||||
get totalItems() {
|
||||
return this.items.reduce((sum, item) => sum + item.quantity, 0);
|
||||
},
|
||||
|
||||
get shipping() {
|
||||
// Free shipping over €50
|
||||
return this.subtotal >= 50 ? 0 : 5.99;
|
||||
},
|
||||
get subtotal() {
|
||||
return this.items.reduce((sum, item) =>
|
||||
sum + (parseFloat(item.price) * item.quantity), 0
|
||||
);
|
||||
},
|
||||
|
||||
get total() {
|
||||
return this.subtotal + this.shipping;
|
||||
},
|
||||
get shipping() {
|
||||
// Free shipping over €50
|
||||
return this.subtotal >= 50 ? 0 : 5.99;
|
||||
},
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
console.log('[SHOP] Cart page initializing...');
|
||||
await this.loadCart();
|
||||
},
|
||||
get total() {
|
||||
return this.subtotal + this.shipping;
|
||||
},
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
console.log('[SHOP] Cart page initializing...');
|
||||
|
||||
// Call parent init to set up sessionId
|
||||
if (baseData.init) {
|
||||
baseData.init.call(this);
|
||||
}
|
||||
|
||||
await this.loadCart();
|
||||
},
|
||||
|
||||
// Load cart from API
|
||||
async loadCart() {
|
||||
@@ -302,7 +311,8 @@ document.addEventListener('alpine:init', () => {
|
||||
window.location.href = '{{ base_url }}shop/checkout';
|
||||
}
|
||||
}
|
||||
}));
|
||||
};
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user