Compare commits

...

2 Commits

4 changed files with 36 additions and 17 deletions

View File

@ -1,7 +1,7 @@
{
"name": "slinicraftet204/notifyifavail",
"description": "benachrichtigt Kunden, sobald ein Produkt wieder verfügbar ist",
"version": "0.1.519",
"version": "0.1.526",
"type": "shopware-platform-plugin",
"license": "MIT",
"authors": [
@ -21,8 +21,8 @@
"extra": {
"shopware-plugin-class": "NotifyIfAvail\\NotifyIfAvail",
"label": {
"de-DE": "NotifyIfAvail (von Nils G.|SLINI)",
"en-GB": "NotifyIfAvail (by Nils G.|SLINI)"
"de-DE": "NotifyIfAvail (Canary)",
"en-GB": "NotifyIfAvail (Canary)"
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -6,13 +6,17 @@
<div id="product-notify-container" class="product-notify-container mt-3" style="display: none;">
<h3>{{ "NotifyIfAvail.notify_me"|trans }}</h3>
{% if app.customer %}
{% if context.customer is defined and context.customer %}
<!-- Eingeloggter Benutzer: Zeige E-Mail-Adresse -->
<p id="user-email-display" data-customer-email="{{ context.customer.email }}">
Eingeloggt als: {{ context.customer.email }}
</p>
<button class="btn btn-primary w-100 notify-me-button"
data-product-id="{{ product.id }}"
data-customer-email="{{ app.customer.email }}">
data-product-id="{{ product.id }}">
{{ "NotifyIfAvail.notify_me"|trans }}
</button>
{% else %}
<!-- Gast: Zeige Eingabefeld -->
<input type="email" id="notify-me-email" class="form-control mb-2"
placeholder="{{ 'NotifyIfAvail.email_placeholder'|trans }}" required>
<button class="btn btn-primary w-100 notify-me-button"
@ -23,24 +27,39 @@
</div>
<script>
console.log("🔹 NotifyMe Script geladen!");
document.addEventListener('DOMContentLoaded', function () {
const notifyContainer = document.getElementById('product-notify-container');
const cartButton = document.querySelector('.btn-buy'); // Prüft, ob der Warenkorb-Button existiert
const cartButton = document.querySelector('.btn-buy');
const emailInput = document.getElementById('notify-me-email');
const emailDisplay = document.getElementById('user-email-display');
const notifyButton = document.querySelector('.notify-me-button');
// Button nur anzeigen, wenn KEIN Warenkorb-Button existiert
if (!cartButton) {
if (!cartButton && notifyContainer) {
notifyContainer.style.display = 'block';
}
document.querySelectorAll('.notify-me-button').forEach(button => {
button.addEventListener('click', function () {
let email;
const productId = this.dataset.productId;
// Falls der Benutzer eingeloggt ist, E-Mail abrufen
if (emailDisplay && emailDisplay.dataset.customerEmail) {
console.log("✅ Benutzer eingeloggt als:", emailDisplay.dataset.customerEmail);
emailInput.style.display = 'none'; // Eingabefeld ausblenden
notifyButton.setAttribute('data-customer-email', emailDisplay.dataset.customerEmail);
} else {
console.log("❌ Kein Benutzer eingeloggt.");
}
if (this.dataset.customerEmail) {
email = this.dataset.customerEmail;
// Event-Listener für den Button
document.body.addEventListener('click', function (event) {
if (event.target.classList.contains('notify-me-button')) {
let email;
const productId = event.target.dataset.productId;
if (event.target.dataset.customerEmail) {
email = event.target.dataset.customerEmail;
} else {
email = document.getElementById('notify-me-email').value;
email = emailInput.value;
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
alert("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
@ -55,8 +74,8 @@
})
.then(response => response.json())
.then(data => alert(data.message))
.catch(error => console.error('Error:', error));
});
.catch(error => console.error('⚠ Fehler:", error'));
}
});
});
</script>