Skip to content

Commit

Permalink
Merge pull request #125 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release 2.4.1
  • Loading branch information
jolelievre authored Mar 22, 2023
2 parents c0bc96c + ded2bf2 commit 3145d0c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 35 deletions.
18 changes: 10 additions & 8 deletions MailAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public static function sendCustomerAlert($id_product, $id_product_attribute)
{
$link = new Link();
$context = Context::getContext()->cloneContext();
$id_product = (int) $id_product;
$id_product_attribute = (int) $id_product_attribute;
$customers = self::getCustomers($id_product, $id_product_attribute);

foreach ($customers as $customer) {
Expand All @@ -179,7 +181,7 @@ public static function sendCustomerAlert($id_product, $id_product_attribute)
$context->shop->id = $id_shop;
$context->language->id = $id_lang;

$product = new Product((int) $id_product, false, $id_lang, $id_shop);
$product = new Product($id_product, false, $id_lang, $id_shop);
$product_name = Product::getProductName($product->id, $id_product_attribute, $id_lang);
$product_link = $link->getProductLink($product, $product->link_rewrite, null, null, $id_lang, $id_shop, $id_product_attribute);
$template_vars = [
Expand All @@ -189,11 +191,11 @@ public static function sendCustomerAlert($id_product, $id_product_attribute)

if ($customer['id_customer']) {
$customer = new Customer((int) $customer['id_customer']);
$customer_email = $customer->email;
$customer_email = (string) $customer->email;
$customer_id = (int) $customer->id;
} else {
$customer_id = 0;
$customer_email = $customer['customer_email'];
$customer_email = (string) $customer['customer_email'];
}

$iso = Language::getIsoById($id_lang);
Expand All @@ -209,7 +211,7 @@ public static function sendCustomerAlert($id_product, $id_product_attribute)
'customer_qty',
$translator->trans('Product available', [], 'Emails.Subject', $locale),
$template_vars,
(string) $customer_email,
$customer_email,
null,
(string) Configuration::get('PS_SHOP_EMAIL', null, null, $id_shop),
(string) Configuration::get('PS_SHOP_NAME', null, null, $id_shop),
Expand Down Expand Up @@ -246,10 +248,10 @@ public static function sendCustomerAlert($id_product, $id_product_attribute)
);

self::deleteAlert(
(int) $customer_id,
(string) $customer_email,
(int) $id_product,
(int) $id_product_attribute,
$customer_id,
$customer_email,
$id_product,
$id_product_attribute,
$id_shop
);
}
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_emailalerts</name>
<displayName><![CDATA[Mail alerts]]></displayName>
<version><![CDATA[2.4.0]]></version>
<version><![CDATA[2.4.1]]></version>
<description><![CDATA[Sends e-mail notifications to customers and merchants regarding stock and order modifications.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
Expand Down
22 changes: 11 additions & 11 deletions controllers/front/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function processAdd()
exit(json_encode(
[
'error' => true,
'message' => $this->trans('Your e-mail address is invalid', [], 'Modules.Emailalerts.Shop'),
'message' => $this->trans('Your email address is invalid.', [], 'Modules.Emailalerts.Shop'),
]
));
}
Expand All @@ -117,26 +117,26 @@ public function processAdd()
exit(json_encode(
[
'error' => true,
'message' => $this->trans('You already have an alert for this product', [], 'Modules.Emailalerts.Shop'),
'message' => $this->trans('You already have set an alert for this product.', [], 'Modules.Emailalerts.Shop'),
]
));
} elseif (!Validate::isLoadedObject($product)) {
exit(json_encode(
[
'error' => true,
'message' => $this->trans('Your e-mail address is invalid', [], 'Modules.Emailalerts.Shop'),
'message' => $this->trans('Your email address is invalid.', [], 'Modules.Emailalerts.Shop'),
]
));
}

$mail_alert = new MailAlert();

$mail_alert->id_customer = (int) $id_customer;
$mail_alert->customer_email = (string) $customer_email;
$mail_alert->id_product = (int) $id_product;
$mail_alert->id_product_attribute = (int) $id_product_attribute;
$mail_alert->id_shop = (int) $id_shop;
$mail_alert->id_lang = (int) $id_lang;
$mail_alert->id_customer = $id_customer;
$mail_alert->customer_email = $customer_email;
$mail_alert->id_product = $id_product;
$mail_alert->id_product_attribute = $id_product_attribute;
$mail_alert->id_shop = $id_shop;
$mail_alert->id_lang = $id_lang;

if ($mail_alert->add() !== false) {
exit(json_encode(
Expand All @@ -150,7 +150,7 @@ public function processAdd()
exit(json_encode(
[
'error' => true,
'message' => $this->trans('Your e-mail address is invalid', [], 'Modules.Emailalerts.Shop'),
'message' => $this->trans('Your email address is invalid.', [], 'Modules.Emailalerts.Shop'),
]
));
}
Expand All @@ -172,7 +172,7 @@ public function processCheck()

$id_product_attribute = (int) Tools::getValue('id_product_attribute');

if (MailAlert::customerHasNotification((int) $id_customer, (int) $id_product, (int) $id_product_attribute, (int) $this->context->shop->id)) {
if (MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute, (int) $this->context->shop->id)) {
exit('1');
}

Expand Down
45 changes: 32 additions & 13 deletions ps_emailalerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct()
{
$this->name = 'ps_emailalerts';
$this->tab = 'administration';
$this->version = '2.4.0';
$this->version = '2.4.1';
$this->author = 'PrestaShop';
$this->need_instance = 0;

Expand Down Expand Up @@ -111,6 +111,7 @@ public function install($delete_params = true)
!$this->registerHook('actionProductCoverage') ||
!$this->registerHook('actionOrderReturn') ||
!$this->registerHook('actionOrderEdited') ||
!$this->registerHook('registerGDPRConsent') ||
!$this->registerHook('actionDeleteGDPRCustomer') ||
!$this->registerHook('actionExportGDPRData') ||
!$this->registerHook('displayProductAdditionalInfo') ||
Expand Down Expand Up @@ -240,7 +241,7 @@ protected function postProcess()

// Check new order e-mails (if setting is active)
if ($new_order_flag && empty($new_order_emails)) {
$errors[] = $this->trans('Please type one (or more) email address for the new order notification', [], 'Modules.Emailalerts.Admin');
$errors[] = $this->trans('Please enter one (or more) email address for the new order notification.', [], 'Modules.Emailalerts.Admin');
} else {
$new_order_emails = explode(self::__MA_MAIL_DELIMITER__, $new_order_emails);
foreach ($new_order_emails as $k => $email) {
Expand All @@ -258,13 +259,13 @@ protected function postProcess()
$new_order_emails = implode(self::__MA_MAIL_DELIMITER__, $new_order_emails);

if (!Configuration::updateValue('MA_MERCHANT_ORDER_EMAILS', (string) $new_order_emails)) {
$errors[] = $this->trans('Cannot update new order emails', [], 'Modules.Emailalerts.Admin');
$errors[] = $this->trans('Cannot update new order emails.', [], 'Modules.Emailalerts.Admin');
}
}

// Check out of stock e-mails (if setting is active)
if ($outofstock_flag && empty($outofstock_emails)) {
$errors[] = $this->trans('Please type one (or more) email address for the out of stock notifications', [], 'Modules.Emailalerts.Admin');
$errors[] = $this->trans('Please enter one (or more) email address for "out of stock" notifications.', [], 'Modules.Emailalerts.Admin');
} else {
$outofstock_emails = explode(self::__MA_MAIL_DELIMITER__, $outofstock_emails);
foreach ($outofstock_emails as $k => $email) {
Expand All @@ -282,13 +283,13 @@ protected function postProcess()
$outofstock_emails = implode(self::__MA_MAIL_DELIMITER__, $outofstock_emails);

if (!Configuration::updateValue('MA_MERCHANT_OOS_EMAILS', (string) $outofstock_emails)) {
$errors[] = $this->trans('Cannot update out of stock emails', [], 'Modules.Emailalerts.Admin');
$errors[] = $this->trans('Cannot update email for "out of stock" notifications.', [], 'Modules.Emailalerts.Admin');
}
}

// Check return slip e-mails (if setting is active)
if ($return_slip_flag && empty($return_slip_emails)) {
$errors[] = $this->trans('Please type one (or more) email address for return slip notifications', [], 'Modules.Emailalerts.Admin');
$errors[] = $this->trans('Please enter one (or more) email address for "return slip" notifications.', [], 'Modules.Emailalerts.Admin');
} else {
$return_slip_emails = explode(self::__MA_MAIL_DELIMITER__, $return_slip_emails);
foreach ($return_slip_emails as $k => $email) {
Expand All @@ -306,7 +307,7 @@ protected function postProcess()
$return_slip_emails = implode(self::__MA_MAIL_DELIMITER__, $return_slip_emails);

if (!Configuration::updateValue('MA_RETURN_SLIP_EMAILS', (string) $return_slip_emails)) {
$errors[] = $this->trans('Cannot update return slip emails', [], 'Modules.Emailalerts.Admin');
$errors[] = $this->trans('Cannot update "return slip" emails.', [], 'Modules.Emailalerts.Admin');
}
}

Expand Down Expand Up @@ -645,6 +646,11 @@ public function hookDisplayProductAdditionalInfo($params)

public function hookActionUpdateQuantity($params)
{
// Do not send email if stock did not change
if (isset($params['delta_quantity']) && (int) $params['delta_quantity'] === 0) {
return;
}

$id_product = (int) $params['id_product'];
$id_product_attribute = (int) $params['id_product_attribute'];

Expand Down Expand Up @@ -1149,8 +1155,8 @@ public function renderForm()
'type' => 'emailalerts_tags',
'label' => $this->trans('Send to:', [], 'Modules.Emailalerts.Admin'),
'name' => 'MA_MERCHANT_ORDER_EMAILS',
'placeholder' => $this->trans('Add e-mail', [], 'Modules.Emailalerts.Admin'),
'desc' => $this->trans('Write one or more e-mail, use \'Return\' or comma to separate each e-mail', [], 'Modules.Emailalerts.Admin'),
'placeholder' => $this->trans('Add email', [], 'Modules.Emailalerts.Admin'),
'desc' => $this->trans('Enter one or more email address. Use \'Return\' or a comma to separate each address.', [], 'Modules.Emailalerts.Admin'),
],
[
'type' => 'switch',
Expand All @@ -1175,8 +1181,8 @@ public function renderForm()
'type' => 'emailalerts_tags',
'label' => $this->trans('Send to:', [], 'Modules.Emailalerts.Admin'),
'name' => 'MA_MERCHANT_OOS_EMAILS',
'placeholder' => $this->trans('Add e-mail', [], 'Modules.Emailalerts.Admin'),
'desc' => $this->trans('Write one or more e-mail, use \'Return\' or comma to separate each e-mail', [], 'Modules.Emailalerts.Admin'),
'placeholder' => $this->trans('Add email', [], 'Modules.Emailalerts.Admin'),
'desc' => $this->trans('Enter one or more email address. Use \'Return\' or a comma to separate each address.', [], 'Modules.Emailalerts.Admin'),
],
[
'type' => 'text',
Expand Down Expand Up @@ -1239,8 +1245,8 @@ public function renderForm()
'type' => 'emailalerts_tags',
'label' => $this->trans('Send to:', [], 'Modules.Emailalerts.Admin'),
'name' => 'MA_RETURN_SLIP_EMAILS',
'placeholder' => $this->trans('Add e-mail', [], 'Modules.Emailalerts.Admin'),
'desc' => $this->trans('Write one or more e-mail, use \'Return\' or comma to separate each e-mail', [], 'Modules.Emailalerts.Admin'),
'placeholder' => $this->trans('Add email', [], 'Modules.Emailalerts.Admin'),
'desc' => $this->trans('Enter one or more email address. Use \'Return\' or a comma to separate each address.', [], 'Modules.Emailalerts.Admin'),
];

$fields_form_2 = [
Expand Down Expand Up @@ -1323,6 +1329,19 @@ public function getConfigFieldsValues()
];
}

/**
* empty listener for registerGDPRConsent hook
*/
public function hookRegisterGDPRConsent()
{
/*
* registerGDPRConsent is a special kind of hook that doesn't need a listener, see :
* https://build.prestashop.com/howtos/module/how-to-make-your-module-compliant-with-prestashop-official-gdpr-compliance-module/
* However since Prestashop 1.7.8, modules must implement a listener for all the hooks they register:
* a check is made at module installation.
*/
}

public function isUsingNewTranslationSystem()
{
return true;
Expand Down
33 changes: 33 additions & 0 deletions upgrade/upgrade-2.4.1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* 2007-2022 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2022 PrestaShop SA
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_')) {
exit;
}

function upgrade_module_2_4_1($object)
{
return $object->registerHook('registerGDPRConsent');
}
2 changes: 1 addition & 1 deletion views/templates/front/mailalerts-account-line.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</div>
</a>
<a href="#"
title="{l s='Remove mail alert' d='Modules.Emailalerts.Shop'}"
title="{l s='Delete email alert' d='Modules.Emailalerts.Shop'}"
class="js-remove-email-alert btn btn-link col-xs-2"
rel="js-id-emailalerts-{$mailAlert.id_product|intval}-{$mailAlert.id_product_attribute|intval}"
data-url="{url entity='module' name='ps_emailalerts' controller='actions' params=['process' => 'remove']}">
Expand Down
2 changes: 1 addition & 1 deletion views/templates/hook/product.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</button>
<div class="js-mailalert-alerts"></div>
{else}
<article class="mt-1 alert alert-info" role="alert">{l s='You will be notified when available' d='Modules.Emailalerts.Shop'}</article>
<article class="mt-1 alert alert-info" role="alert">{l s='You will be notified when this product is available.' d='Modules.Emailalerts.Shop'}</article>
{/if}
</div>
</div>

0 comments on commit 3145d0c

Please sign in to comment.