Fix Newsletter unsubscribe box
This commit is contained in:
@@ -38,6 +38,22 @@ class Ps_EmailsubscriptionSubscriptionModuleFrontController extends ModuleFrontC
|
||||
*/
|
||||
public function postProcess()
|
||||
{
|
||||
// One-click unsubscribe via email link
|
||||
if (Tools::getValue('unsubscribe')) {
|
||||
$email = Tools::getValue('email', '');
|
||||
$token = Tools::getValue('token', '');
|
||||
|
||||
$msg = $this->module->unsubscribeByLink($email, $token);
|
||||
|
||||
// показати повідомлення на сторінці
|
||||
$this->variables['value'] = $email;
|
||||
$this->variables['msg'] = $msg;
|
||||
$this->variables['nw_error'] = false;
|
||||
|
||||
// можна одразу рендерити template як і зараз
|
||||
return;
|
||||
}
|
||||
|
||||
$this->variables['value'] = Tools::getValue('email', '');
|
||||
$this->variables['msg'] = '';
|
||||
$this->variables['conditions'] = Configuration::get('NW_CONDITIONS', $this->context->language->id);
|
||||
|
||||
@@ -305,9 +305,40 @@
|
||||
</div>
|
||||
<!--[if mso | IE]></td></tr></table></td></tr><![endif]-->
|
||||
<!-- MESSAGE BOX ENDING -->
|
||||
|
||||
|
||||
|
||||
<div style="margin:0px auto;max-width:604px;">
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; direction: ltr; font-size: 0px; padding: 15px 50px 40px; text-align: center;" align="center">
|
||||
<!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:504px;" ><![endif]-->
|
||||
<div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;" align="left" width="100%">
|
||||
<table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #fefefe; border: 1px solid #DFDFDF; vertical-align: top; padding-top: 10px; padding-bottom: 10px;" bgcolor="#fefefe">
|
||||
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;" width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="left" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-size: 0px; padding: 10px 25px; word-break: break-word;">
|
||||
<div style="font-family:Open sans, arial, sans-serif;font-size:10px;line-height:18px;text-align:center;color:#aeaeae;" align="center">
|
||||
Nie chcemy zakłócać Twojego spokoju ????<br>
|
||||
Jeśli wolisz, by nasze wiadomości Cię nie budziły, <a href="{unsubscribe_url}" style="text-decoration:underline;color:#aeaeae;font-weight:400;">Wypisz mnie</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]></td></tr></table><![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!--[if mso | IE]></table><![endif]-->
|
||||
</td>
|
||||
|
||||
@@ -308,7 +308,40 @@
|
||||
<!--[if mso | IE]></td></tr></table></td></tr><![endif]-->
|
||||
<!-- MESSAGE BOX ENDING -->
|
||||
|
||||
|
||||
<div style="margin:0px auto;max-width:604px;">
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; direction: ltr; font-size: 0px; padding: 15px 50px 40px; text-align: center;" align="center">
|
||||
<!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:504px;" ><![endif]-->
|
||||
<div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;" align="left" width="100%">
|
||||
<table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #fefefe; border: 1px solid #DFDFDF; vertical-align: top; padding-top: 10px; padding-bottom: 10px;" bgcolor="#fefefe">
|
||||
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;" width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="left" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-size: 0px; padding: 10px 25px; word-break: break-word;">
|
||||
<div style="font-family:Open sans, arial, sans-serif;font-size:10px;line-height:18px;text-align:center;color:#aeaeae;" align="center">
|
||||
Nie chcemy zakłócać Twojego spokoju ????<br>
|
||||
Jeśli wolisz, by nasze wiadomości Cię nie budziły, <a href="{unsubscribe_url}" style="text-decoration:underline;color:#aeaeae;font-weight:400;">Wypisz mnie</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]></td></tr></table><![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<!--[if mso | IE]></table><![endif]-->
|
||||
|
||||
@@ -296,7 +296,12 @@
|
||||
Teraz będziesz na bieżąco z najlepszymi ofertami, nowościami i inspiracjami dotyczącymi aranżacji wnętrz.<br><br>
|
||||
🎁 Oto Twój kod rabatowy na pierwsze zakupy: <span class="label" style="font-weight: 700;">{discount}</span><br><br>
|
||||
Wykorzystaj go na <strong>Masimmo.pl</strong> i stwórz wnętrze swoich marzeń już dziś!
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div style="font-family:Open sans, arial, sans-serif;font-size:10px;line-height:18px;text-align:center;color:#aeaeae;" align="center">
|
||||
Nie chcemy zakłócać Twojego spokoju ????<br>
|
||||
Jeśli wolisz, by nasze wiadomości Cię nie budziły, <a href="{unsubscribe_url}" style="text-decoration:underline;color:#aeaeae;font-weight:400;">Wypisz mnie</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -7,6 +7,7 @@ Witaj,
|
||||
Zapisz się do newslettera
|
||||
|
||||
Dziękujemy za subskrypcję naszego newslettera. Z przyjemnością oferujemy następujący kupon: {discount}
|
||||
Aby wypisać się z newslettera, kliknij tutaj:{unsubscribe_url}
|
||||
|
||||
[{shop_name}]({shop_url})
|
||||
|
||||
|
||||
@@ -577,15 +577,26 @@ class Ps_Emailsubscription extends Module implements WidgetInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function unregister($email, $register_status)
|
||||
function unregister($email, $register_status)
|
||||
{
|
||||
$email = pSQL((string) $email);
|
||||
|
||||
if ($register_status == self::GUEST_REGISTERED) {
|
||||
$sql = 'DELETE FROM ' . _DB_PREFIX_ . 'emailsubscription WHERE `email` = \'' . pSQL($_POST['email']) . '\' AND id_shop = ' . $this->context->shop->id;
|
||||
$sql = 'DELETE FROM ' . _DB_PREFIX_ . 'emailsubscription
|
||||
WHERE `email` = \'' . $email . '\'
|
||||
AND id_shop = ' . (int) $this->context->shop->id;
|
||||
} elseif ($register_status == self::CUSTOMER_REGISTERED) {
|
||||
$sql = 'UPDATE ' . _DB_PREFIX_ . 'customer SET `newsletter` = 0 WHERE `email` = \'' . pSQL($_POST['email']) . '\' AND id_shop = ' . $this->context->shop->id;
|
||||
$sql = 'UPDATE ' . _DB_PREFIX_ . 'customer
|
||||
SET `newsletter` = 0,
|
||||
`newsletter_date_add` = NULL,
|
||||
`ip_registration_newsletter` = NULL
|
||||
WHERE `email` = \'' . $email . '\'
|
||||
AND id_shop = ' . (int) $this->context->shop->id;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($sql) || !Db::getInstance()->execute($sql)) {
|
||||
if (!Db::getInstance()->execute($sql)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -710,6 +721,65 @@ class Ps_Emailsubscription extends Module implements WidgetInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* One-click unsubscribe token (independent from date_add/newsletter_date_add).
|
||||
*/
|
||||
protected function getUnsubscribeToken($email)
|
||||
{
|
||||
// stable secret based on shop config
|
||||
$salt = (string) Configuration::get('NW_SALT');
|
||||
$rand = (string) Configuration::get('PS_NEWSLETTER_RAND');
|
||||
|
||||
return md5(strtolower(trim($email)) . '|' . $salt . '|' . $rand);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds unsubscribe URL for emails.
|
||||
*/
|
||||
public function getUnsubscribeUrl($email)
|
||||
{
|
||||
$token = $this->getUnsubscribeToken($email);
|
||||
|
||||
return $this->context->link->getModuleLink(
|
||||
'ps_emailsubscription',
|
||||
'subscription',
|
||||
[
|
||||
'unsubscribe' => 1,
|
||||
'email' => $email,
|
||||
'token' => $token,
|
||||
],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe by email+token (used by one-click link).
|
||||
*/
|
||||
public function unsubscribeByLink($email, $token)
|
||||
{
|
||||
$email = trim((string) $email);
|
||||
$token = (string) $token;
|
||||
|
||||
if (!Validate::isEmail($email)) {
|
||||
return $this->trans('Invalid email address.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
|
||||
if ($token !== $this->getUnsubscribeToken($email)) {
|
||||
return $this->trans('This link is invalid or expired.', [], 'Shop.Notifications.Error');
|
||||
}
|
||||
|
||||
$register_status = $this->isNewsletterRegistered($email);
|
||||
if ($register_status < 1) {
|
||||
return $this->trans('This email address is not registered.', [], 'Modules.Emailsubscription.Shop');
|
||||
}
|
||||
|
||||
if (!$this->unregister($email, $register_status)) {
|
||||
return $this->trans('An error occurred while attempting to unsubscribe.', [], 'Modules.Emailsubscription.Shop');
|
||||
}
|
||||
|
||||
return $this->trans('Unsubscription successful.', [], 'Modules.Emailsubscription.Shop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the registration process to the newsletter.
|
||||
*
|
||||
@@ -796,6 +866,7 @@ class Ps_Emailsubscription extends Module implements WidgetInterface
|
||||
),
|
||||
[
|
||||
'{discount}' => $code,
|
||||
'{unsubscribe_url}' => $this->getUnsubscribeUrl($email),
|
||||
],
|
||||
$email,
|
||||
null,
|
||||
|
||||
Reference in New Issue
Block a user