From dbca1414883ba232d8f17ac8867e66275b0337e5 Mon Sep 17 00:00:00 2001 From: SLINIcraftet204 Date: Tue, 11 Mar 2025 16:29:24 +0100 Subject: [PATCH] changed some code --- composer.json | 2 +- src/Resources/public/js/notify-me.plugin.js | 18 ++++---- .../component/buy-widget/buy-widget.html.twig | 46 +++++++++---------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 7d79ab6..b868e9e 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/src/Resources/public/js/notify-me.plugin.js b/src/Resources/public/js/notify-me.plugin.js index c9b9667..455fdb9 100644 --- a/src/Resources/public/js/notify-me.plugin.js +++ b/src/Resources/public/js/notify-me.plugin.js @@ -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); - } } diff --git a/src/Resources/views/storefront/component/buy-widget/buy-widget.html.twig b/src/Resources/views/storefront/component/buy-widget/buy-widget.html.twig index 79e6ab7..79cbd86 100644 --- a/src/Resources/views/storefront/component/buy-widget/buy-widget.html.twig +++ b/src/Resources/views/storefront/component/buy-widget/buy-widget.html.twig @@ -1,28 +1,26 @@ -{% sw_extends '@Storefront/storefront/component/buy-widget/buy-widget.html.twig' %} - {% block buy_widget_price %} - {{ parent() }} +
+ {% sw_include '@Storefront/storefront/component/buy-widget/buy-widget-price.html.twig' %} - {% if not product.available or product.stock <= 0 %} -
-

{{ "NotifyIfAvail.notify_me"|trans }}

+ {% if not product.available or product.stock <= 0 %} +
+

{{ "NotifyIfAvail.notify_me"|trans }}

- {% if app.customer %} - - - {% else %} - - - - {% endif %} -
- {% endif %} + {% if app.customer %} + + + {% else %} + + + + {% endif %} +
+ {% endif %} +
{% endblock %} +