Fix Alpine timing: use alpine:init + Alpine.data() so productDetail is registered before Alpine starts
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 7s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 07:14:29 +02:00
co-authored by Claude Sonnet 4.6
parent 0a98740877
commit 6d16a6b0f9
+11 -7
View File
@@ -2,7 +2,7 @@
@section('title', $product->name) @section('title', $product->name)
@section('content') @section('content')
@php $firstImageUrl = $product->images->count() ? asset('storage/'.$product->images->first()->path) : ''; @endphp @php $firstImageUrl = $product->images->count() ? asset('storage/'.$product->images->first()->path) : ''; @endphp
<div class="grid grid-cols-1 md:grid-cols-2 gap-10 mb-12" x-data="productDetail(@json($product->variants), @json($firstImageUrl))"> <div class="grid grid-cols-1 md:grid-cols-2 gap-10 mb-12" x-data="productDetail">
{{-- Bilder --}} {{-- Bilder --}}
<div> <div>
@@ -110,13 +110,17 @@
@endif @endif
<script> <script>
function productDetail(variants, firstImage) { document.addEventListener('alpine:init', () => {
return { const variants = @json($product->variants->load('attributeValues'));
const firstImage = @json($firstImageUrl);
const basePrice = {{ $product->base_price }};
Alpine.data('productDetail', () => ({
variants, variants,
selectedAttrs: {}, selectedAttrs: {},
selectedVariant: null, selectedVariant: null,
mainImage: firstImage, mainImage: firstImage,
currentPrice: {{ $product->base_price }}, currentPrice: basePrice,
selectAttr(name, id) { selectAttr(name, id) {
this.selectedAttrs[name] = id; this.selectedAttrs[name] = id;
this.findVariant(); this.findVariant();
@@ -128,13 +132,13 @@ function productDetail(variants, firstImage) {
return selectedIds.every(id => ids.includes(id)) && ids.length === selectedIds.length; return selectedIds.every(id => ids.includes(id)) && ids.length === selectedIds.length;
}); });
if (this.selectedVariant) { if (this.selectedVariant) {
this.currentPrice = this.selectedVariant.price_override ?? {{ $product->base_price }}; this.currentPrice = this.selectedVariant.price_override ?? basePrice;
} }
}, },
formatPrice(p) { formatPrice(p) {
return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(p); return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(p);
} }
} }));
} });
</script> </script>
@endsection @endsection