21
21
use Magento \Framework \App \RequestInterface ;
22
22
use Magento \Framework \Controller \Result \Redirect ;
23
23
use Magento \Framework \Exception \LocalizedException ;
24
+ use Magento \Framework \Message \MessageInterface ;
24
25
use Magento \Framework \Phrase ;
25
26
use Magento \Store \Model \StoreManagerInterface ;
26
27
use Magento \Customer \Api \AccountManagementInterface ;
@@ -118,6 +119,11 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht
118
119
*/
119
120
protected $ session ;
120
121
122
+ /**
123
+ * @var StoreManagerInterface
124
+ */
125
+ protected $ storeManager ;
126
+
121
127
/**
122
128
* @var AccountRedirect
123
129
*/
@@ -365,20 +371,19 @@ public function execute()
365
371
);
366
372
$ confirmationStatus = $ this ->accountManagement ->getConfirmationStatus ($ customer ->getId ());
367
373
if ($ confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED ) {
368
- $ email = $ this ->customerUrl ->getEmailConfirmationUrl ($ customer ->getEmail ());
369
- // @codingStandardsIgnoreStart
370
- $ this ->messageManager ->addSuccess (
371
- __ (
372
- 'You must confirm your account. Please check your email for the confirmation link or <a href="%1">click here</a> for a new link. ' ,
373
- $ email
374
- )
374
+ $ this ->messageManager ->addComplexSuccessMessage (
375
+ 'confirmAccountSuccessMessage ' ,
376
+ [
377
+ 'url ' => $ this ->customerUrl ->getEmailConfirmationUrl ($ customer ->getEmail ()),
378
+ ]
375
379
);
376
- // @codingStandardsIgnoreEnd
377
380
$ url = $ this ->urlModel ->getUrl ('*/*/index ' , ['_secure ' => true ]);
378
381
$ resultRedirect ->setUrl ($ this ->_redirect ->success ($ url ));
379
382
} else {
380
383
$ this ->session ->setCustomerDataAsLoggedIn ($ customer );
381
- $ this ->messageManager ->addSuccess ($ this ->getSuccessMessage ());
384
+
385
+ $ this ->messageManager ->addMessage ($ this ->getMessageManagerSuccessMessage ());
386
+
382
387
$ requestedRedirect = $ this ->accountRedirect ->getRedirectCookie ();
383
388
if (!$ this ->scopeConfig ->getValue ('customer/startup/redirect_dashboard ' ) && $ requestedRedirect ) {
384
389
$ resultRedirect ->setUrl ($ this ->_redirect ->success ($ requestedRedirect ));
@@ -395,23 +400,21 @@ public function execute()
395
400
396
401
return $ resultRedirect ;
397
402
} catch (StateException $ e ) {
398
- $ url = $ this ->urlModel -> getUrl ( ' customer/account/forgotpassword ' );
399
- // @codingStandardsIgnoreStart
400
- $ message = __ (
401
- ' There is already an account with this email address. If you are sure that it is your email address, <a href="%1">click here</a> to get your password and access your account. ' ,
402
- $ url
403
+ $ this ->messageManager -> addComplexErrorMessage (
404
+ ' customerAlreadyExistsErrorMessage ' ,
405
+ [
406
+ ' url ' => $ this -> urlModel -> getUrl ( ' customer/ account/forgotpassword ' ) ,
407
+ ]
403
408
);
404
- // @codingStandardsIgnoreEnd
405
- $ this ->messageManager ->addError ($ message );
406
409
} catch (InputException $ e ) {
407
- $ this ->messageManager ->addError ( $ this -> escaper -> escapeHtml ( $ e ->getMessage () ));
410
+ $ this ->messageManager ->addErrorMessage ( $ e ->getMessage ());
408
411
foreach ($ e ->getErrors () as $ error ) {
409
- $ this ->messageManager ->addError ( $ this -> escaper -> escapeHtml ( $ error ->getMessage () ));
412
+ $ this ->messageManager ->addErrorMessage ( $ error ->getMessage ());
410
413
}
411
414
} catch (LocalizedException $ e ) {
412
- $ this ->messageManager ->addError ( $ this -> escaper -> escapeHtml ( $ e ->getMessage () ));
415
+ $ this ->messageManager ->addErrorMessage ( $ e ->getMessage ());
413
416
} catch (\Exception $ e ) {
414
- $ this ->messageManager ->addException ($ e , __ ('We can \'t save the customer. ' ));
417
+ $ this ->messageManager ->addExceptionMessage ($ e , __ ('We can \'t save the customer. ' ));
415
418
}
416
419
417
420
$ this ->session ->setCustomerFormData ($ this ->getRequest ()->getPostValue ());
@@ -437,6 +440,8 @@ protected function checkPasswordConfirmation($password, $confirmation)
437
440
/**
438
441
* Retrieve success message
439
442
*
443
+ * @deprecated
444
+ * @see getMessageManagerSuccessMessage()
440
445
* @return string
441
446
*/
442
447
protected function getSuccessMessage ()
@@ -462,4 +467,37 @@ protected function getSuccessMessage()
462
467
}
463
468
return $ message ;
464
469
}
470
+
471
+ /**
472
+ * Retrieve success message manager message
473
+ *
474
+ * @return MessageInterface
475
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
476
+ */
477
+ protected function getMessageManagerSuccessMessage (): MessageInterface
478
+ {
479
+ if ($ this ->addressHelper ->isVatValidationEnabled ()) {
480
+ if ($ this ->addressHelper ->getTaxCalculationAddressType () == Address::TYPE_SHIPPING ) {
481
+ $ identifier = 'customerVatShippingAddressSuccessMessage ' ;
482
+ } else {
483
+ $ identifier = 'customerVatBillingAddressSuccessMessage ' ;
484
+ }
485
+
486
+ $ message = $ this ->messageManager
487
+ ->createMessage (MessageInterface::TYPE_SUCCESS , $ identifier )
488
+ ->setData (
489
+ [
490
+ 'url ' => $ this ->urlModel ->getUrl ('customer/address/edit ' ),
491
+ ]
492
+ );
493
+ } else {
494
+ $ message = $ this ->messageManager
495
+ ->createMessage (MessageInterface::TYPE_SUCCESS )
496
+ ->setText (
497
+ __ ('Thank you for registering with %1. ' , $ this ->storeManager ->getStore ()->getFrontendName ())
498
+ );
499
+ }
500
+
501
+ return $ message ;
502
+ }
465
503
}
0 commit comments