changed Plugin to canary state, fixed and tested some thing in the shitty buy-widget class

This commit is contained in:
Nils 2025-03-14 14:52:16 +01:00
parent 51f52983a3
commit 9b8e4e465a
Signed by: slinicraftet204
GPG Key ID: 78E12696BAFC2A4B
4 changed files with 34 additions and 12 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

@ -2,17 +2,20 @@
{% block buy_widget_price %} {% block buy_widget_price %}
{{ parent() }} {{ parent() }}
{{ dump(page.customer) }}
<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 app.customer %}
<!-- Eingeloggter Benutzer: Email wird dynamisch eingefügt -->
<p id="user-email-display" style="display: none;"></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: Eingabefeld + Button -->
<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,22 +26,41 @@
</div> </div>
<script> <script>
document.addEventListener('DOMContentLoaded', function () { console.log("NotifyMe Script geladen!");
document.addEventListener('DOMContentLoaded', async 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'); // Prüft, ob der Warenkorb-Button existiert
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.style.display = 'block'; notifyContainer.style.display = 'block';
// Falls Nutzer eingeloggt ist, versuche die E-Mail-Adresse zu bekommen
try {
let response = await fetch('/account/profile');
let html = await response.text();
let emailMatch = html.match(/type="email"[^>]*value="([^"]+)"/);
if (emailMatch) {
emailDisplay.innerText = `Eingeloggt als: ${emailMatch[1]}`;
emailDisplay.style.display = 'block';
notifyButton.setAttribute('data-customer-email', emailMatch[1]);
}
} catch (error) {
console.error("Fehler beim Abrufen der Kunden-E-Mail:", error);
}
} }
document.querySelectorAll('.notify-me-button').forEach(button => { // Event-Listener für alle Benachrichtigungsbuttons
button.addEventListener('click', function () { document.body.addEventListener('click', function (event) {
if (event.target.classList.contains('notify-me-button')) {
let email; let email;
const productId = this.dataset.productId; const productId = event.target.dataset.productId;
if (this.dataset.customerEmail) { if (event.target.dataset.customerEmail) {
email = this.dataset.customerEmail; email = event.target.dataset.customerEmail;
} else { } else {
email = document.getElementById('notify-me-email').value; email = document.getElementById('notify-me-email').value;
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@ -56,7 +78,7 @@
.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('Error:', error));
}); }
}); });
}); });
</script> </script>