Skip to content

Commit 185d1b3

Browse files
committed
Email subscription jquery removed
1 parent 240c54e commit 185d1b3

File tree

5 files changed

+83
-2
lines changed

5 files changed

+83
-2
lines changed

_dev/js/utils/http/useHttpRequest.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ const useHttpRequest = (url, options = {}, addons = []) => {
2222
options.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
2323
}
2424

25+
// Set default accept header
26+
if (!(options.headers?.['accept'])) {
27+
options.headers['accept'] = 'application/json, text/javascript, */*;';
28+
}
29+
2530
// Set default X-Requested-With header
2631
if (!(options.headers?.['X-Requested-With'])) {
2732
options.headers['X-Requested-With'] = 'XMLHttpRequest';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* 2007-2020 PrestaShop.
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
8+
* that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* https://opensource.org/licenses/AFL-3.0
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to license@prestashop.com so we can send you a copy immediately.
14+
*
15+
* DISCLAIMER
16+
*
17+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
18+
* versions in the future. If you wish to customize PrestaShop for your
19+
* needs please refer to http://www.prestashop.com for more information.
20+
*
21+
* @author PrestaShop SA <contact@prestashop.com>
22+
* @copyright 2007-2020 PrestaShop SA
23+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
24+
* International Registered Trademark & Property of PrestaShop SA
25+
*/
26+
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
27+
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
28+
29+
header('Cache-Control: no-store, no-cache, must-revalidate');
30+
header('Cache-Control: post-check=0, pre-check=0', false);
31+
header('Pragma: no-cache');
32+
33+
header('Location: ../');
34+
exit;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
DOMReady(() => {
3+
const ALERT_BLOCK_CLASS = 'js-newsletter-form-alert';
4+
const buildAlertBlock = (msg, type) => parseToHtml(`<div class="alert alert-${type} ${ALERT_BLOCK_CLASS}">${msg}</div>`);
5+
const handleSubmit = (e) => {
6+
e.preventDefault();
7+
8+
// psemailsubscription_subscription - is a global variable
9+
if (typeof psemailsubscription_subscription === 'undefined') {
10+
return true;
11+
}
12+
13+
const alertBlock = document.querySelector(`.${ALERT_BLOCK_CLASS}`);
14+
const form = e.target;
15+
const data = fromSerialize(form);
16+
17+
const { request } = useHttpRequest(psemailsubscription_subscription);
18+
19+
request
20+
.body(data)
21+
.post()
22+
.json((resp) => {
23+
alertBlock?.remove();
24+
25+
if (resp.nw_error) {
26+
form.prepend(buildAlertBlock(resp.msg, 'danger'));
27+
} else {
28+
form.prepend(buildAlertBlock(resp.msg, 'success'));
29+
}
30+
});
31+
}
32+
33+
each('.js-newsletter-form', (el) => {
34+
eventHandlerOn(el, 'submit', handleSubmit);
35+
})
36+
})

modules/ps_emailsubscription/views/templates/hook/ps_emailsubscription-column.tpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
*}
2525

2626
<div class="block_newsletter" id="blockEmailSubscription_{$hookName}">
27-
<form action="{$urls.current_url}#blockEmailSubscription_{$hookName}" method="post">
27+
<form
28+
class="js-newsletter-form"
29+
action="{$urls.current_url}#blockEmailSubscription_{$hookName}"
30+
method="post">
2831
<div class="row">
2932
<p id="block-newsletter-label" class="col-12">{l s='Get our latest news and special sales' d='Shop.Theme.Global'}</p>
3033
<div class="col-12 mb-1">

modules/ps_emailsubscription/views/templates/hook/ps_emailsubscription.tpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
<div class="row">
2828
<p id="block-newsletter-label" class="col-md-5 col-12">{l s='Get our latest news and special sales' d='Shop.Theme.Global'}</p>
2929
<div class="col-md-7 col-12">
30-
<form action="{$urls.current_url}#blockEmailSubscription_{$hookName}" method="post">
30+
<form
31+
class="js-newsletter-form"
32+
action="{$urls.current_url}#blockEmailSubscription_{$hookName}"
33+
method="post">
3134
<div class="row">
3235
<div class="col-12">
3336
<div class="input-group js-parent-focus">

0 commit comments

Comments
 (0)