Compare commits

..

No commits in common. "9863afe09aa75d59c4d5bd5fc4d84ebc8ce6cc28" and "51f52983a3d8dbb4d8bcf1e2d2e13b9f31e0034d" have entirely different histories.

4 changed files with 16 additions and 35 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.526", "version": "0.1.519",
"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 (Canary)", "de-DE": "NotifyIfAvail (von Nils G.|SLINI)",
"en-GB": "NotifyIfAvail (Canary)" "en-GB": "NotifyIfAvail (by Nils G.|SLINI)"
} }
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

View File

@ -6,17 +6,13 @@
<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 context.customer is defined and context.customer %} {% if app.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"
@ -27,39 +23,24 @@
</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'); const cartButton = document.querySelector('.btn-buy'); // Prüft, ob der Warenkorb-Button existiert
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 && notifyContainer) { if (!cartButton) {
notifyContainer.style.display = 'block'; notifyContainer.style.display = 'block';
} }
// Falls der Benutzer eingeloggt ist, E-Mail abrufen document.querySelectorAll('.notify-me-button').forEach(button => {
if (emailDisplay && emailDisplay.dataset.customerEmail) { button.addEventListener('click', function () {
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.");
}
// Event-Listener für den Button
document.body.addEventListener('click', function (event) {
if (event.target.classList.contains('notify-me-button')) {
let email; let email;
const productId = event.target.dataset.productId; const productId = this.dataset.productId;
if (event.target.dataset.customerEmail) { if (this.dataset.customerEmail) {
email = event.target.dataset.customerEmail; email = this.dataset.customerEmail;
} else { } else {
email = emailInput.value; email = document.getElementById('notify-me-email').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.");
@ -74,8 +55,8 @@
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => alert(data.message)) .then(data => alert(data.message))
.catch(error => console.error('⚠ Fehler:", error')); .catch(error => console.error('Error:', error));
} });
}); });
}); });
</script> </script>