changed some code
This commit is contained in:
parent
a84436c2eb
commit
dbca141488
@ -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.499",
|
"version": "0.1.501",
|
||||||
"type": "shopware-platform-plugin",
|
"type": "shopware-platform-plugin",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import Plugin from 'src/plugin-system/plugin.class';
|
import Plugin from 'src/plugin-system/plugin.class';
|
||||||
|
|
||||||
export default class NotifyMePlugin extends Plugin {
|
export default class NotifyMe extends Plugin {
|
||||||
init() {
|
init() {
|
||||||
this.notifyButton = document.getElementById('notify-me-button');
|
this.notifyButton = this.el;
|
||||||
this.emailInput = document.getElementById('notify-me-email');
|
this.emailInput = document.getElementById('notify-me-email');
|
||||||
this.submitButton = document.getElementById('submit-notify');
|
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) {
|
submitForm(isLoggedIn) {
|
||||||
let email;
|
let email;
|
||||||
const productId = this.notifyButton?.dataset.productId || this.submitButton?.dataset.productId;
|
const productId = this.notifyButton.dataset.productId;
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
email = this.notifyButton.dataset.customerEmail;
|
email = this.notifyButton.dataset.customerEmail;
|
||||||
} else {
|
} else {
|
||||||
email = this.emailInput.value.trim();
|
email = this.emailInput.value;
|
||||||
if (!this.validateEmail(email)) {
|
if (!this.validateEmail(email)) {
|
||||||
alert("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
|
alert("Bitte geben Sie eine gültige E-Mail-Adresse ein.");
|
||||||
return;
|
return;
|
||||||
@ -42,9 +47,4 @@ export default class NotifyMePlugin extends Plugin {
|
|||||||
.then(data => alert(data.message))
|
.then(data => alert(data.message))
|
||||||
.catch(error => console.error('Error:', error));
|
.catch(error => console.error('Error:', error));
|
||||||
}
|
}
|
||||||
|
|
||||||
validateEmail(email) {
|
|
||||||
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
||||||
return emailPattern.test(email);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,26 @@
|
|||||||
{% sw_extends '@Storefront/storefront/component/buy-widget/buy-widget.html.twig' %}
|
|
||||||
|
|
||||||
{% block buy_widget_price %}
|
{% 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 %}
|
{% if not product.available or product.stock <= 0 %}
|
||||||
<div class="product-notify-container mt-3">
|
<div class="product-notify-container mt-3">
|
||||||
<h3>{{ "NotifyIfAvail.notify_me"|trans }}</h3>
|
<h3>{{ "NotifyIfAvail.notify_me"|trans }}</h3>
|
||||||
|
|
||||||
{% if app.customer %}
|
{% if app.customer %}
|
||||||
<!-- Eingeloggter Benutzer: Nur Button anzeigen -->
|
<!-- Eingeloggter Benutzer -->
|
||||||
<button class="btn btn-primary w-100" id="notify-me-button"
|
<button class="btn btn-primary w-100" id="notify-me-button" data-product-id="{{ product.id }}" data-customer-email="{{ app.customer.email }}">
|
||||||
data-product-id="{{ product.id }}"
|
{{ "NotifyIfAvail.notify_me"|trans }}
|
||||||
data-customer-email="{{ app.customer.email }}">
|
</button>
|
||||||
{{ "NotifyIfAvail.notify_me"|trans }}
|
{% else %}
|
||||||
</button>
|
<!-- Gast/ Nicht eingeloggter Benutzer -->
|
||||||
{% else %}
|
<input type="email" id="notify-me-email" class="form-control mb-2"
|
||||||
<!-- Gast: Nur Eingabefeld + Button anzeigen -->
|
placeholder="{{ 'NotifyIfAvail.email_placeholder'|trans }}" required>
|
||||||
<input type="email" id="notify-me-email" class="form-control mb-2"
|
<button class="btn btn-primary w-100" id="submit-notify" data-product-id="{{ product.id }}">
|
||||||
placeholder="{{ 'NotifyIfAvail.email_placeholder'|trans }}" required>
|
{{ "NotifyIfAvail.notify_me"|trans }}
|
||||||
<button class="btn btn-primary w-100" id="submit-notify"
|
</button>
|
||||||
data-product-id="{{ product.id }}">
|
{% endif %}
|
||||||
{{ "NotifyIfAvail.notify_me"|trans }}
|
</div>
|
||||||
</button>
|
{% endif %}
|
||||||
{% endif %}
|
</div>
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user