Skip to content

Commit c514365

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-96125' into EPAM-PR-23
2 parents 3866c94 + 500fd02 commit c514365

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

app/code/Magento/Customer/Api/AccountManagementInterface.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ interface AccountManagementInterface
3131
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
3232
* @param string $password
3333
* @param string $redirectUrl
34+
* @param string[] $extensions
3435
* @return \Magento\Customer\Api\Data\CustomerInterface
3536
* @throws \Magento\Framework\Exception\LocalizedException
3637
*/
3738
public function createAccount(
3839
\Magento\Customer\Api\Data\CustomerInterface $customer,
3940
$password = null,
40-
$redirectUrl = ''
41+
$redirectUrl = '',
42+
$extensions = []
4143
);
4244

4345
/**
@@ -48,6 +50,7 @@ public function createAccount(
4850
* @param string $hash Password hash that we can save directly
4951
* @param string $redirectUrl URL fed to welcome email templates. Can be used by templates to, for example, direct
5052
* the customer to a product they were looking at after pressing confirmation link.
53+
* @param string[] $extensions
5154
* @return \Magento\Customer\Api\Data\CustomerInterface
5255
* @throws \Magento\Framework\Exception\InputException If bad input is provided
5356
* @throws \Magento\Framework\Exception\State\InputMismatchException If the provided email is already used
@@ -56,7 +59,8 @@ public function createAccount(
5659
public function createAccountWithPasswordHash(
5760
\Magento\Customer\Api\Data\CustomerInterface $customer,
5861
$hash,
59-
$redirectUrl = ''
62+
$redirectUrl = '',
63+
$extensions = []
6064
);
6165

6266
/**

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ public function getConfirmationStatus($customerId)
794794
/**
795795
* @inheritdoc
796796
*/
797-
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '')
797+
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '', $extensions = [])
798798
{
799799
if ($password !== null) {
800800
$this->checkPasswordStrength($password);
@@ -810,16 +810,20 @@ public function createAccount(CustomerInterface $customer, $password = null, $re
810810
} else {
811811
$hash = null;
812812
}
813-
return $this->createAccountWithPasswordHash($customer, $hash, $redirectUrl);
813+
return $this->createAccountWithPasswordHash($customer, $hash, $redirectUrl, $extensions);
814814
}
815815

816816
/**
817817
* @inheritdoc
818818
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
819819
* @SuppressWarnings(PHPMD.NPathComplexity)
820820
*/
821-
public function createAccountWithPasswordHash(CustomerInterface $customer, $hash, $redirectUrl = '')
822-
{
821+
public function createAccountWithPasswordHash(
822+
CustomerInterface $customer,
823+
$hash,
824+
$redirectUrl = '',
825+
$extensions = []
826+
) {
823827
// This logic allows an existing customer to be added to a different store. No new account is created.
824828
// The plan is to move this logic into a new method called something like 'registerAccountWithStore'
825829
if ($customer->getId()) {
@@ -892,7 +896,7 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
892896
$customer = $this->customerRepository->getById($customer->getId());
893897
$newLinkToken = $this->mathRandom->getUniqueHash();
894898
$this->changeResetPasswordLinkToken($customer, $newLinkToken);
895-
$this->sendEmailConfirmation($customer, $redirectUrl);
899+
$this->sendEmailConfirmation($customer, $redirectUrl, $extensions);
896900

897901
return $customer;
898902
}
@@ -920,9 +924,10 @@ public function getDefaultShippingAddress($customerId)
920924
*
921925
* @param CustomerInterface $customer
922926
* @param string $redirectUrl
927+
* @param array $extensions
923928
* @return void
924929
*/
925-
protected function sendEmailConfirmation(CustomerInterface $customer, $redirectUrl)
930+
protected function sendEmailConfirmation(CustomerInterface $customer, $redirectUrl, $extensions = [])
926931
{
927932
try {
928933
$hash = $this->customerRegistry->retrieveSecureData($customer->getId())->getPasswordHash();
@@ -932,7 +937,14 @@ protected function sendEmailConfirmation(CustomerInterface $customer, $redirectU
932937
} elseif ($hash == '') {
933938
$templateType = self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD;
934939
}
935-
$this->getEmailNotification()->newAccount($customer, $templateType, $redirectUrl, $customer->getStoreId());
940+
$this->getEmailNotification()->newAccount(
941+
$customer,
942+
$templateType,
943+
$redirectUrl,
944+
$customer->getStoreId(),
945+
null,
946+
$extensions
947+
);
936948
} catch (MailException $e) {
937949
// If we are not able to send a new account email, this should be ignored
938950
$this->logger->critical($e);

app/code/Magento/Customer/Model/EmailNotification.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\Framework\Exception\LocalizedException;
1818

1919
/**
20+
* Class for notification customer.
21+
*
2022
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2123
*/
2224
class EmailNotification implements EmailNotificationInterface
@@ -63,6 +65,8 @@ class EmailNotification implements EmailNotificationInterface
6365
self::NEW_ACCOUNT_EMAIL_CONFIRMATION => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
6466
];
6567

68+
const CUSTOMER_CONFIRM_URL = 'customer/account/confirm/';
69+
6670
/**#@-*/
6771

6872
/**#@-*/
@@ -362,6 +366,7 @@ public function passwordResetConfirmation(CustomerInterface $customer)
362366
* @param string $backUrl
363367
* @param string $storeId
364368
* @param string $sendemailStoreId
369+
* @param array $extensions
365370
* @return void
366371
* @throws LocalizedException
367372
*/
@@ -370,7 +375,8 @@ public function newAccount(
370375
$type = self::NEW_ACCOUNT_EMAIL_REGISTERED,
371376
$backUrl = '',
372377
$storeId = 0,
373-
$sendemailStoreId = null
378+
$sendemailStoreId = null,
379+
$extensions = []
374380
) {
375381
$types = self::TEMPLATE_TYPES;
376382

@@ -388,11 +394,26 @@ public function newAccount(
388394

389395
$customerEmailData = $this->getFullCustomerObject($customer);
390396

397+
$templateVars = [
398+
'customer' => $customerEmailData,
399+
'back_url' => $backUrl,
400+
'store' => $store
401+
];
402+
if ($type == self::NEW_ACCOUNT_EMAIL_CONFIRMATION) {
403+
if (empty($extensions)) {
404+
$templateVars['url'] = self::CUSTOMER_CONFIRM_URL;
405+
$templateVars['extensions'] = $extensions;
406+
} else {
407+
$templateVars['url'] = $extensions['url'];
408+
$templateVars['extensions'] = $extensions['extension_info'];
409+
}
410+
}
411+
391412
$this->sendEmailTemplate(
392413
$customer,
393414
$types[$type],
394415
self::XML_PATH_REGISTER_EMAIL_IDENTITY,
395-
['customer' => $customerEmailData, 'back_url' => $backUrl, 'store' => $store],
416+
$templateVars,
396417
$storeId
397418
);
398419
}

app/code/Magento/Customer/view/frontend/email/account_new_confirmation.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"var this.getUrl($store, 'customer/account/confirm/', [_query:[id:$customer.id, key:$customer.confirmation, back_url:$back_url]])":"Account Confirmation URL",
1010
"var this.getUrl($store, 'customer/account/')":"Customer Account URL",
1111
"var customer.email":"Customer Email",
12-
"var customer.name":"Customer Name"
12+
"var customer.name":"Customer Name",
13+
"var extensions":"Extensions",
14+
"var url":"Url"
1315
} @-->
1416

1517
{{template config_path="design/email/header_template"}}
@@ -23,7 +25,7 @@
2325
<table class="inner-wrapper" border="0" cellspacing="0" cellpadding="0" align="center">
2426
<tr>
2527
<td align="center">
26-
<a href="{{var this.getUrl($store,'customer/account/confirm/',[_query:[id:$customer.id,key:$customer.confirmation,back_url:$back_url],_nosid:1])}}" target="_blank">{{trans "Confirm Your Account"}}</a>
28+
<a href="{{var this.getUrl($store,$url,[_query:[id:$customer.id,key:$customer.confirmation,extensions:$extensions,back_url:$back_url],_nosid:1])}}" target="_blank">{{trans "Confirm Your Account"}}</a>
2729
</td>
2830
</tr>
2931
</table>

0 commit comments

Comments
 (0)