changed Plugin to canary state, fixed and tested some thing in the shitty buy-widget class
This commit is contained in:
parent
51f52983a3
commit
9b8e4e465a
@ -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 |
BIN
src/Resources/config/release_plugin.png
Normal file
BIN
src/Resources/config/release_plugin.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
@ -2,17 +2,20 @@
|
||||
|
||||
{% block buy_widget_price %}
|
||||
{{ parent() }}
|
||||
{{ dump(page.customer) }}
|
||||
|
||||
<div id="product-notify-container" class="product-notify-container mt-3" style="display: none;">
|
||||
<h3>{{ "NotifyIfAvail.notify_me"|trans }}</h3>
|
||||
|
||||
{% 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"
|
||||
data-product-id="{{ product.id }}"
|
||||
data-customer-email="{{ app.customer.email }}">
|
||||
data-product-id="{{ product.id }}">
|
||||
{{ "NotifyIfAvail.notify_me"|trans }}
|
||||
</button>
|
||||
{% else %}
|
||||
<!-- Gast: Eingabefeld + Button -->
|
||||
<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,22 +26,41 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
console.log("NotifyMe Script geladen!");
|
||||
document.addEventListener('DOMContentLoaded', async function () {
|
||||
const notifyContainer = document.getElementById('product-notify-container');
|
||||
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
|
||||
if (!cartButton) {
|
||||
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 => {
|
||||
button.addEventListener('click', function () {
|
||||
// Event-Listener für alle Benachrichtigungsbuttons
|
||||
document.body.addEventListener('click', function (event) {
|
||||
if (event.target.classList.contains('notify-me-button')) {
|
||||
let email;
|
||||
const productId = this.dataset.productId;
|
||||
const productId = event.target.dataset.productId;
|
||||
|
||||
if (this.dataset.customerEmail) {
|
||||
email = this.dataset.customerEmail;
|
||||
if (event.target.dataset.customerEmail) {
|
||||
email = event.target.dataset.customerEmail;
|
||||
} else {
|
||||
email = document.getElementById('notify-me-email').value;
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
@ -56,7 +78,7 @@
|
||||
.then(response => response.json())
|
||||
.then(data => alert(data.message))
|
||||
.catch(error => console.error('Error:', error));
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user