changed some code

This commit is contained in:
Nils 2025-03-11 16:29:24 +01:00
parent a84436c2eb
commit dbca141488
Signed by: slinicraftet204
GPG Key ID: 78E12696BAFC2A4B
3 changed files with 32 additions and 34 deletions

View File

@ -1,7 +1,7 @@
{
"name": "slinicraftet204/notifyifavail",
"description": "benachrichtigt Kunden, sobald ein Produkt wieder verfügbar ist",
"version": "0.1.499",
"version": "0.1.501",
"type": "shopware-platform-plugin",
"license": "MIT",
"authors": [

View File

@ -1,8 +1,8 @@
import Plugin from 'src/plugin-system/plugin.class';
export default class NotifyMePlugin extends Plugin {
export default class NotifyMe extends Plugin {
init() {
this.notifyButton = document.getElementById('notify-me-button');
this.notifyButton = this.el;
this.emailInput = document.getElementById('notify-me-email');
this.submitButton = document.getElementById('submit-notify');
@ -19,14 +19,19 @@ export default class NotifyMePlugin extends Plugin {
}
}
validateEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
submitForm(isLoggedIn) {
let email;
const productId = this.notifyButton?.dataset.productId || this.submitButton?.dataset.productId;
const productId = this.notifyButton.dataset.productId;
if (isLoggedIn) {
email = this.notifyButton.dataset.customerEmail;
} else {
email = this.emailInput.value.trim();
email = this.emailInput.value;
if (!this.validateEmail(email)) {
alert("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
return;
@ -42,9 +47,4 @@ export default class NotifyMePlugin extends Plugin {
.then(data => alert(data.message))
.catch(error => console.error('Error:', error));
}
validateEmail(email) {
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailPattern.test(email);
}
}

View File

@ -1,28 +1,26 @@
{% sw_extends '@Storefront/storefront/component/buy-widget/buy-widget.html.twig' %}
{% block buy_widget_price %}
{{ parent() }}
<div class="product-detail-price-container">
{% sw_include '@Storefront/storefront/component/buy-widget/buy-widget-price.html.twig' %}
{% if not product.available or product.stock <= 0 %}
<div class="product-notify-container mt-3">
<h3>{{ "NotifyIfAvail.notify_me"|trans }}</h3>
{% if not product.available or product.stock <= 0 %}
<div class="product-notify-container mt-3">
<h3>{{ "NotifyIfAvail.notify_me"|trans }}</h3>
{% if app.customer %}
<!-- Eingeloggter Benutzer: Nur Button anzeigen -->
<button class="btn btn-primary w-100" id="notify-me-button"
data-product-id="{{ product.id }}"
data-customer-email="{{ app.customer.email }}">
{{ "NotifyIfAvail.notify_me"|trans }}
</button>
{% else %}
<!-- Gast: Nur Eingabefeld + Button anzeigen -->
<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" id="submit-notify"
data-product-id="{{ product.id }}">
{{ "NotifyIfAvail.notify_me"|trans }}
</button>
{% endif %}
</div>
{% endif %}
{% if app.customer %}
<!-- Eingeloggter Benutzer -->
<button class="btn btn-primary w-100" id="notify-me-button" data-product-id="{{ product.id }}" data-customer-email="{{ app.customer.email }}">
{{ "NotifyIfAvail.notify_me"|trans }}
</button>
{% else %}
<!-- Gast/ Nicht eingeloggter Benutzer -->
<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" id="submit-notify" data-product-id="{{ product.id }}">
{{ "NotifyIfAvail.notify_me"|trans }}
</button>
{% endif %}
</div>
{% endif %}
</div>
{% endblock %}