diff --git a/MailAlert.php b/MailAlert.php index 24b2b66..6503a9f 100644 --- a/MailAlert.php +++ b/MailAlert.php @@ -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) { @@ -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 = [ @@ -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); @@ -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), @@ -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 ); } diff --git a/config.xml b/config.xml index 22912d1..56237a6 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_emailalerts - + diff --git a/controllers/front/actions.php b/controllers/front/actions.php index 69e3660..69abb49 100644 --- a/controllers/front/actions.php +++ b/controllers/front/actions.php @@ -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'), ] )); } @@ -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( @@ -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'), ] )); } @@ -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'); } diff --git a/ps_emailalerts.php b/ps_emailalerts.php index 3a2dd93..0ecebae 100644 --- a/ps_emailalerts.php +++ b/ps_emailalerts.php @@ -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; @@ -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') || @@ -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) { @@ -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) { @@ -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) { @@ -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'); } } @@ -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']; @@ -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', @@ -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', @@ -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 = [ @@ -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; diff --git a/upgrade/upgrade-2.4.1.php b/upgrade/upgrade-2.4.1.php new file mode 100644 index 0000000..a3541f8 --- /dev/null +++ b/upgrade/upgrade-2.4.1.php @@ -0,0 +1,33 @@ + + * @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'); +} diff --git a/views/templates/front/mailalerts-account-line.tpl b/views/templates/front/mailalerts-account-line.tpl index 691d21c..7455e1a 100644 --- a/views/templates/front/mailalerts-account-line.tpl +++ b/views/templates/front/mailalerts-account-line.tpl @@ -32,7 +32,7 @@ diff --git a/views/templates/hook/product.tpl b/views/templates/hook/product.tpl index 7487cee..5db4984 100644 --- a/views/templates/hook/product.tpl +++ b/views/templates/hook/product.tpl @@ -44,7 +44,7 @@
{else} - + {/if}