[-] FO : #FSCFV-903 : Add Mail confirmation sending when subscribing to the newsletter via Accont creation or edition
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@15198 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -106,12 +106,12 @@ class AuthControllerCore extends FrontController
|
|||||||
$countries = Country::getCountries($this->context->language->id, true);
|
$countries = Country::getCountries($this->context->language->id, true);
|
||||||
|
|
||||||
$this->context->smarty->assign(array(
|
$this->context->smarty->assign(array(
|
||||||
'inOrderProcess' => true,
|
'inOrderProcess' => true,
|
||||||
'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'),
|
'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'),
|
||||||
'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'),
|
'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'),
|
||||||
'sl_country' => (int)Tools::getValue('id_country', Configuration::get('PS_COUNTRY_DEFAULT')),
|
'sl_country' => (int)Tools::getValue('id_country', Configuration::get('PS_COUNTRY_DEFAULT')),
|
||||||
'countries' => $countries
|
'countries' => $countries
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,17 +127,17 @@ class AuthControllerCore extends FrontController
|
|||||||
|
|
||||||
// Call a hook to display more information on form
|
// Call a hook to display more information on form
|
||||||
$this->context->smarty->assign(array(
|
$this->context->smarty->assign(array(
|
||||||
'HOOK_CREATE_ACCOUNT_FORM' => Hook::exec('displayCustomerAccountForm'),
|
'HOOK_CREATE_ACCOUNT_FORM' => Hook::exec('displayCustomerAccountForm'),
|
||||||
'HOOK_CREATE_ACCOUNT_TOP' => Hook::exec('displayCustomerAccountFormTop')
|
'HOOK_CREATE_ACCOUNT_TOP' => Hook::exec('displayCustomerAccountFormTop')
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($this->ajax)
|
if ($this->ajax)
|
||||||
{
|
{
|
||||||
// Call a hook to display more information on form
|
// Call a hook to display more information on form
|
||||||
$this->context->smarty->assign(array(
|
$this->context->smarty->assign(array(
|
||||||
'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'),
|
'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'),
|
||||||
'genders' => Gender::getGenders()
|
'genders' => Gender::getGenders()
|
||||||
));
|
));
|
||||||
|
|
||||||
$return = array(
|
$return = array(
|
||||||
'hasError' => !empty($this->errors),
|
'hasError' => !empty($this->errors),
|
||||||
@@ -168,13 +168,13 @@ class AuthControllerCore extends FrontController
|
|||||||
$days = Tools::dateDays();
|
$days = Tools::dateDays();
|
||||||
|
|
||||||
$this->context->smarty->assign(array(
|
$this->context->smarty->assign(array(
|
||||||
'years' => $years,
|
'years' => $years,
|
||||||
'sl_year' => (isset($selectedYears) ? $selectedYears : 0),
|
'sl_year' => (isset($selectedYears) ? $selectedYears : 0),
|
||||||
'months' => $months,
|
'months' => $months,
|
||||||
'sl_month' => (isset($selectedMonths) ? $selectedMonths : 0),
|
'sl_month' => (isset($selectedMonths) ? $selectedMonths : 0),
|
||||||
'days' => $days,
|
'days' => $days,
|
||||||
'sl_day' => (isset($selectedDays) ? $selectedDays : 0)
|
'sl_day' => (isset($selectedDays) ? $selectedDays : 0)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,16 +192,16 @@ class AuthControllerCore extends FrontController
|
|||||||
* But for now it's a bug !
|
* But for now it's a bug !
|
||||||
* @see : bug #6968
|
* @see : bug #6968
|
||||||
* @link:http://www.prestashop.com/bug_tracker/view/6968/
|
* @link:http://www.prestashop.com/bug_tracker/view/6968/
|
||||||
elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
||||||
{
|
{
|
||||||
$array = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
$array = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
if (Validate::isLanguageIsoCode($array[0]))
|
if (Validate::isLanguageIsoCode($array[0]))
|
||||||
{
|
{
|
||||||
$selectedCountry = Country::getByIso($array[0]);
|
$selectedCountry = Country::getByIso($array[0]);
|
||||||
if (!$selectedCountry)
|
if (!$selectedCountry)
|
||||||
$selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT'));
|
$selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT'));
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
if (!isset($selectedCountry))
|
if (!isset($selectedCountry))
|
||||||
$selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT'));
|
$selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT'));
|
||||||
|
|
||||||
@@ -210,11 +210,11 @@ class AuthControllerCore extends FrontController
|
|||||||
else
|
else
|
||||||
$countries = Country::getCountries($this->context->language->id, true);
|
$countries = Country::getCountries($this->context->language->id, true);
|
||||||
$this->context->smarty->assign(array(
|
$this->context->smarty->assign(array(
|
||||||
'countries' => $countries,
|
'countries' => $countries,
|
||||||
'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'),
|
'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'),
|
||||||
'sl_country' => (isset($selectedCountry) ? $selectedCountry : 0),
|
'sl_country' => (isset($selectedCountry) ? $selectedCountry : 0),
|
||||||
'vat_management' => Configuration::get('VATNUMBER_MANAGEMENT')
|
'vat_management' => Configuration::get('VATNUMBER_MANAGEMENT')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ class AuthControllerCore extends FrontController
|
|||||||
|
|
||||||
foreach ($addressFormat as $addressline)
|
foreach ($addressFormat as $addressline)
|
||||||
foreach (explode(' ', $addressline) as $addressItem)
|
foreach (explode(' ', $addressline) as $addressItem)
|
||||||
$addressItems[] = trim($addressItem);
|
$addressItems[] = trim($addressItem);
|
||||||
|
|
||||||
// Add missing require fields for a new user susbscription form
|
// Add missing require fields for a new user susbscription form
|
||||||
foreach ($requireFormFieldsList as $fieldName)
|
foreach ($requireFormFieldsList as $fieldName)
|
||||||
@@ -347,6 +347,26 @@ class AuthControllerCore extends FrontController
|
|||||||
$this->context->smarty->assign('authentification_error', $this->errors);
|
$this->context->smarty->assign('authentification_error', $this->errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the newsletter settings and set the customer infos.
|
||||||
|
*
|
||||||
|
* @param Customer $customer Reference on the customer Object.
|
||||||
|
*
|
||||||
|
* @note At this point, the email has been validated.
|
||||||
|
*/
|
||||||
|
protected function processCustomerNewsletter(&$customer)
|
||||||
|
{
|
||||||
|
if (Tools::getValue('newsletter'))
|
||||||
|
{
|
||||||
|
$customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr());
|
||||||
|
$customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s'));
|
||||||
|
|
||||||
|
if ($module_newsletter = Module::getInstanceByName('blocknewsletter'))
|
||||||
|
if ($module_newsletter->active)
|
||||||
|
$module_newsletter->confirmSubscription(Tools::getValue('email'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process submit on an account
|
* Process submit on an account
|
||||||
*/
|
*/
|
||||||
@@ -379,10 +399,7 @@ class AuthControllerCore extends FrontController
|
|||||||
if (!count($this->errors))
|
if (!count($this->errors))
|
||||||
{
|
{
|
||||||
if (Tools::isSubmit('newsletter'))
|
if (Tools::isSubmit('newsletter'))
|
||||||
{
|
$this->processCustomerNewsletter($customer);
|
||||||
$customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr());
|
|
||||||
$customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s'));
|
|
||||||
}
|
|
||||||
$customer->birthday = (empty($_POST['years']) ? '' : (int)$_POST['years'].'-'.(int)$_POST['months'].'-'.(int)$_POST['days']);
|
$customer->birthday = (empty($_POST['years']) ? '' : (int)$_POST['years'].'-'.(int)$_POST['months'].'-'.(int)$_POST['days']);
|
||||||
$customer->active = 1;
|
$customer->active = 1;
|
||||||
// New Guest customer
|
// New Guest customer
|
||||||
@@ -414,9 +431,9 @@ class AuthControllerCore extends FrontController
|
|||||||
|
|
||||||
$this->context->cart->update();
|
$this->context->cart->update();
|
||||||
Hook::exec('actionCustomerAccountAdd', array(
|
Hook::exec('actionCustomerAccountAdd', array(
|
||||||
'_POST' => $_POST,
|
'_POST' => $_POST,
|
||||||
'newCustomer' => $customer
|
'newCustomer' => $customer
|
||||||
));
|
));
|
||||||
if ($this->ajax)
|
if ($this->ajax)
|
||||||
{
|
{
|
||||||
$return = array(
|
$return = array(
|
||||||
@@ -494,10 +511,7 @@ class AuthControllerCore extends FrontController
|
|||||||
if (Customer::customerExists(Tools::getValue('email')))
|
if (Customer::customerExists(Tools::getValue('email')))
|
||||||
$this->errors[] = Tools::displayError('An account is already registered with this e-mail, please enter your password or request a new one.', false);
|
$this->errors[] = Tools::displayError('An account is already registered with this e-mail, please enter your password or request a new one.', false);
|
||||||
if (Tools::isSubmit('newsletter'))
|
if (Tools::isSubmit('newsletter'))
|
||||||
{
|
$this->processCustomerNewsletter($customer);
|
||||||
$customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr());
|
|
||||||
$customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$customer->birthday = (empty($_POST['years']) ? '' : (int)$_POST['years'].'-'.(int)$_POST['months'].'-'.(int)$_POST['days']);
|
$customer->birthday = (empty($_POST['years']) ? '' : (int)$_POST['years'].'-'.(int)$_POST['months'].'-'.(int)$_POST['days']);
|
||||||
if (!count($this->errors))
|
if (!count($this->errors))
|
||||||
@@ -549,9 +563,9 @@ class AuthControllerCore extends FrontController
|
|||||||
// If a logged guest logs in as a customer, the cart secure key was already set and needs to be updated
|
// If a logged guest logs in as a customer, the cart secure key was already set and needs to be updated
|
||||||
$this->context->cart->update();
|
$this->context->cart->update();
|
||||||
Hook::exec('actionCustomerAccountAdd', array(
|
Hook::exec('actionCustomerAccountAdd', array(
|
||||||
'_POST' => $_POST,
|
'_POST' => $_POST,
|
||||||
'newCustomer' => $customer
|
'newCustomer' => $customer
|
||||||
));
|
));
|
||||||
if ($this->ajax)
|
if ($this->ajax)
|
||||||
{
|
{
|
||||||
$return = array(
|
$return = array(
|
||||||
|
|||||||
@@ -44,13 +44,15 @@ class IdentityControllerCore extends FrontController
|
|||||||
*/
|
*/
|
||||||
public function postProcess()
|
public function postProcess()
|
||||||
{
|
{
|
||||||
|
$origin_newsletter = (bool)$this->customer->newsletter;
|
||||||
|
|
||||||
if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days']))
|
if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days']))
|
||||||
$this->customer->birthday = (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']);
|
$this->customer->birthday = (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']);
|
||||||
|
|
||||||
if (Tools::isSubmit('submitIdentity'))
|
if (Tools::isSubmit('submitIdentity'))
|
||||||
{
|
{
|
||||||
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) &&
|
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) &&
|
||||||
!(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == ''))
|
!(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == ''))
|
||||||
$this->errors[] = Tools::displayError('Invalid date of birth');
|
$this->errors[] = Tools::displayError('Invalid date of birth');
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -76,8 +78,14 @@ class IdentityControllerCore extends FrontController
|
|||||||
{
|
{
|
||||||
$this->customer->id_default_group = (int)$prev_id_default_group;
|
$this->customer->id_default_group = (int)$prev_id_default_group;
|
||||||
$this->customer->firstname = Tools::ucfirst(Tools::strtolower($this->customer->firstname));
|
$this->customer->firstname = Tools::ucfirst(Tools::strtolower($this->customer->firstname));
|
||||||
|
|
||||||
if (!isset($_POST['newsletter']))
|
if (!isset($_POST['newsletter']))
|
||||||
$this->customer->newsletter = 0;
|
$this->customer->newsletter = 0;
|
||||||
|
elseif (!$origin_newsletter && isset($_POST['newsletter']))
|
||||||
|
if ($module_newsletter = Module::getInstanceByName('blocknewsletter'))
|
||||||
|
if ($module_newsletter->active)
|
||||||
|
$module_newsletter->confirmSubscription($this->customer->email);
|
||||||
|
|
||||||
if (!isset($_POST['optin']))
|
if (!isset($_POST['optin']))
|
||||||
$this->customer->optin = 0;
|
$this->customer->optin = 0;
|
||||||
if (Tools::getValue('passwd'))
|
if (Tools::getValue('passwd'))
|
||||||
@@ -113,15 +121,15 @@ class IdentityControllerCore extends FrontController
|
|||||||
|
|
||||||
/* Generate years, months and days */
|
/* Generate years, months and days */
|
||||||
$this->context->smarty->assign(array(
|
$this->context->smarty->assign(array(
|
||||||
'years' => Tools::dateYears(),
|
'years' => Tools::dateYears(),
|
||||||
'sl_year' => $birthday[0],
|
'sl_year' => $birthday[0],
|
||||||
'months' => Tools::dateMonths(),
|
'months' => Tools::dateMonths(),
|
||||||
'sl_month' => $birthday[1],
|
'sl_month' => $birthday[1],
|
||||||
'days' => Tools::dateDays(),
|
'days' => Tools::dateDays(),
|
||||||
'sl_day' => $birthday[2],
|
'sl_day' => $birthday[2],
|
||||||
'errors' => $this->errors,
|
'errors' => $this->errors,
|
||||||
'genders' => Gender::getGenders(),
|
'genders' => Gender::getGenders(),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active);
|
$this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active);
|
||||||
|
|
||||||
|
|||||||
@@ -422,6 +422,26 @@ class Blocknewsletter extends Module
|
|||||||
return $this->l('Thank you for subscribing to our newsletter.');
|
return $this->l('Thank you for subscribing to our newsletter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the confirmation mails to the given $email address if needed.
|
||||||
|
*
|
||||||
|
* @param string $email Email where to send the confirmation
|
||||||
|
*
|
||||||
|
* @note the email has been verified and might not yet been registered. Called by AuthController::processCustomerNewsletter
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function confirmSubscription($email)
|
||||||
|
{
|
||||||
|
if ($email)
|
||||||
|
{
|
||||||
|
if ($discount = Configuration::get('NW_VOUCHER_CODE'))
|
||||||
|
$this->sendVoucher($email, $discount);
|
||||||
|
|
||||||
|
if (Configuration::get('NW_CONFIRMATION_EMAIL'))
|
||||||
|
$this->sendConfirmationEmail($email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an email containing a voucher code
|
* Send an email containing a voucher code
|
||||||
* @param string $email
|
* @param string $email
|
||||||
|
|||||||
Reference in New Issue
Block a user