Compare commits

...

2 Commits

4 changed files with 36 additions and 17 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "slinicraftet204/notifyifavail", "name": "slinicraftet204/notifyifavail",
"description": "benachrichtigt Kunden, sobald ein Produkt wieder verfügbar ist", "description": "benachrichtigt Kunden, sobald ein Produkt wieder verfügbar ist",
"version": "0.1.519", "version": "0.1.526",
"type": "shopware-platform-plugin", "type": "shopware-platform-plugin",
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
@ -21,8 +21,8 @@
"extra": { "extra": {
"shopware-plugin-class": "NotifyIfAvail\\NotifyIfAvail", "shopware-plugin-class": "NotifyIfAvail\\NotifyIfAvail",
"label": { "label": {
"de-DE": "NotifyIfAvail (von Nils G.|SLINI)", "de-DE": "NotifyIfAvail (Canary)",
"en-GB": "NotifyIfAvail (by Nils G.|SLINI)" "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;"> <div id="product-notify-container" class="product-notify-container mt-3" style="display: none;">
<h3>{{ "NotifyIfAvail.notify_me"|trans }}</h3> <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" <button class="btn btn-primary w-100 notify-me-button"
data-product-id="{{ product.id }}" data-product-id="{{ product.id }}">
data-customer-email="{{ app.customer.email }}">
{{ "NotifyIfAvail.notify_me"|trans }} {{ "NotifyIfAvail.notify_me"|trans }}
</button> </button>
{% else %} {% else %}
<!-- Gast: Zeige Eingabefeld -->
<input type="email" id="notify-me-email" class="form-control mb-2" <input type="email" id="notify-me-email" class="form-control mb-2"
placeholder="{{ 'NotifyIfAvail.email_placeholder'|trans }}" required> placeholder="{{ 'NotifyIfAvail.email_placeholder'|trans }}" required>
<button class="btn btn-primary w-100 notify-me-button" <button class="btn btn-primary w-100 notify-me-button"
@ -23,24 +27,39 @@
</div> </div>
<script> <script>
console.log("🔹 NotifyMe Script geladen!");
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
const notifyContainer = document.getElementById('product-notify-container'); 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 // Button nur anzeigen, wenn KEIN Warenkorb-Button existiert
if (!cartButton) { if (!cartButton && notifyContainer) {
notifyContainer.style.display = 'block'; notifyContainer.style.display = 'block';
} }
document.querySelectorAll('.notify-me-button').forEach(button => { // Falls der Benutzer eingeloggt ist, E-Mail abrufen
button.addEventListener('click', function () { if (emailDisplay && emailDisplay.dataset.customerEmail) {
let email; console.log("✅ Benutzer eingeloggt als:", emailDisplay.dataset.customerEmail);
const productId = this.dataset.productId; emailInput.style.display = 'none'; // Eingabefeld ausblenden
notifyButton.setAttribute('data-customer-email', emailDisplay.dataset.customerEmail);
} else {
console.log("❌ Kein Benutzer eingeloggt.");
}
if (this.dataset.customerEmail) { // Event-Listener für den Button
email = this.dataset.customerEmail; 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 { } else {
email = document.getElementById('notify-me-email').value; email = emailInput.value;
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) { if (!emailRegex.test(email)) {
alert("Bitte geben Sie eine gültige E-Mail-Adresse ein."); alert("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
@ -55,8 +74,8 @@
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => alert(data.message)) .then(data => alert(data.message))
.catch(error => console.error('Error:', error)); .catch(error => console.error('⚠ Fehler:", error'));
}); }
}); });
}); });
</script> </script>