{% extends 'base.html.twig' %}
{% block title %}Checkout{% endblock %}
{% block body %}
<div class="container my-5">
<!-- Hauptcontainer -->
<div class="row">
<!-- Produktübersicht -->
<section class="col-md-8">
<div class="card h-100 shadow-sm">
<div class="card-body">
{% if cart is not empty %}
<h1 class="mb-4 product-name">{{ product.name }}</h1>
<p class="product-description">{{ product.beschreibung }}</p>
<p><strong>Preis: <span class="product-price">{{ product.preis|number_format(2, ',', '.') }} €</span></strong></p>
{% else %}
<h1 class="mb-4">Keine Produkte im Warenkorb</h1>
<p>Bitte fügen Sie ein Produkt hinzu, um es im Warenkorb anzuzeigen.</p>
{% endif %}
</div>
</div>
</section>
<!-- Kasse -->
<section class="col-md-4">
<div class="card h-100 shadow-sm">
<div class="card-body d-flex flex-column justify-content-between">
<div>
<h4 class="mb-4">Kasse</h4>
<div id="cart-items">
{% if cart is not empty %}
{% set total = 0 %}
<ul class="list-group mb-3">
{% for cart_item in cart %}
<li class="list-group-item d-flex justify-content-between align-items-center">
<span>{{ cart_item.product.name }}</span>
<div>
<span>{{ cart_item.product.preis|number_format(2, ',', '.') }} € x {{ cart_item.quantity }}</span>
<button class="btn btn-sm btn-danger ms-3 remove-from-cart" data-id="{{ cart_item.product.id }}">-</button>
</div>
</li>
{% set total = total + (cart_item.product.preis * cart_item.quantity) %}
{% endfor %}
</ul>
<div class="d-flex justify-content-between mb-3">
<strong>Gesamt:</strong>
<strong id="cart-total">{{ total|number_format(2, ',', '.') }} €</strong>
</div>
{% else %}
<div class="alert alert-warning">
Ihr Warenkorb ist leer.
</div>
{% endif %}
</div>
</div>
<!-- Auswahl der Zahlungsmethoden -->
<form method="post" action="{{ path('shop_checkout_process') }}">
<div class="form-group mb-3">
<label for="payment_method">Zahlungsmethode auswählen:</label>
<select name="payment_method" id="payment_method" class="form-select">
<option value="paypal">PayPal</option>
<option value="stripe">Kreditkarte (Stripe)</option>
</select>
</div>
<button type="submit" class="btn btn-primary btn-lg w-100 mt-3" {% if cart is empty %}disabled{% endif %}>Bezahlen</button>
</form>
</div>
</div>
</section>
</div>
</div>
<!-- Ähnliche Produkte (über volle Breite) -->
<section class="py-5" style="background-color: #f8f9fa;">
<div class="container">
<h2 class="text-center mb-4">Diese Produkte könnten Ihnen auch gefallen</h2>
<div class="row">
{% for similar_product in similar_products %}
<div class="col-md-6 mb-4">
<div class="card h-100 shadow-sm">
<div class="card-body">
<h5 class="card-title">{{ similar_product.name }}</h5>
<p class="card-text">{{ similar_product.beschreibung|length > 50 ? similar_product.beschreibung|slice(0, 50) ~ '...' : similar_product.beschreibung }}</p>
<p class="card-text">
<strong>{{ similar_product.preis|number_format(2, ',', '.') }} €</strong>
</p>
</div>
<div class="card-footer bg-white">
<button class="btn btn-secondary w-100 add-to-cart" data-id="{{ similar_product.id }}">Hinzufügen</button>
</div>
</div>
</div>
{% else %}
<div class="col-12">
<div class="alert alert-warning text-center">
Keine ähnlichen Produkte gefunden.
</div>
</div>
{% endfor %}
</div>
</div>
</section>
<!-- AJAX Script -->
<script>
document.addEventListener('DOMContentLoaded', function() {
// Hinzufügen von Produkten
document.querySelectorAll('.add-to-cart').forEach(button => {
button.addEventListener('click', function() {
let productId = this.getAttribute('data-id');
fetch('/shop/cart/add/' + productId, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
// Aktualisiere den Warenkorb-Bereich
document.getElementById('cart-items').innerHTML = data.cartHtml;
document.getElementById('cart-total').innerText = data.total + ' €';
// Aktualisiere die Produktinformationen, wenn der Warenkorb nicht leer ist
if (data.product) {
document.querySelector('.product-name').innerText = data.product.name;
document.querySelector('.product-description').innerText = data.product.description;
document.querySelector('.product-price').innerText = data.product.price + ' €';
}
});
});
});
// Entfernen von Produkten
document.addEventListener('click', function(event) {
if (event.target.classList.contains('remove-from-cart')) {
let productId = event.target.getAttribute('data-id');
fetch('/shop/cart/remove/' + productId, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
// Aktualisiere den Warenkorb-Bereich
document.getElementById('cart-items').innerHTML = data.cartHtml;
document.getElementById('cart-total').innerText = data.total + ' €';
// Wenn der Warenkorb leer ist, zeige Nachricht an
if (Object.keys(data.cart).length === 0) {
document.querySelector('.product-name').innerText = 'Keine Produkte im Warenkorb';
document.querySelector('.product-description').innerText = '';
document.querySelector('.product-price').innerText = '';
}
});
}
});
});
</script>
{% endblock %}