Edit.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Customer\Controller\Account;
  8. use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
  9. use Magento\Customer\Api\CustomerRepositoryInterface;
  10. use Magento\Framework\Api\DataObjectHelper;
  11. use Magento\Customer\Model\Session;
  12. use Magento\Framework\View\Result\PageFactory;
  13. use Magento\Framework\App\Action\Context;
  14. class Edit extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface
  15. {
  16. /**
  17. * @var \Magento\Customer\Api\CustomerRepositoryInterface
  18. */
  19. protected $customerRepository;
  20. /**
  21. * @var \Magento\Framework\Api\DataObjectHelper
  22. */
  23. protected $dataObjectHelper;
  24. /**
  25. * @var Session
  26. */
  27. protected $session;
  28. /**
  29. * @var PageFactory
  30. */
  31. protected $resultPageFactory;
  32. /**
  33. * @param Context $context
  34. * @param Session $customerSession
  35. * @param PageFactory $resultPageFactory
  36. * @param CustomerRepositoryInterface $customerRepository
  37. * @param DataObjectHelper $dataObjectHelper
  38. */
  39. public function __construct(
  40. Context $context,
  41. Session $customerSession,
  42. PageFactory $resultPageFactory,
  43. CustomerRepositoryInterface $customerRepository,
  44. DataObjectHelper $dataObjectHelper
  45. ) {
  46. $this->session = $customerSession;
  47. $this->resultPageFactory = $resultPageFactory;
  48. $this->customerRepository = $customerRepository;
  49. $this->dataObjectHelper = $dataObjectHelper;
  50. parent::__construct($context);
  51. }
  52. /**
  53. * Forgot customer account information page
  54. *
  55. * @return \Magento\Framework\View\Result\Page
  56. */
  57. public function execute()
  58. {
  59. /** @var \Magento\Framework\View\Result\Page $resultPage */
  60. $resultPage = $this->resultPageFactory->create();
  61. $block = $resultPage->getLayout()->getBlock('customer_edit');
  62. if ($block) {
  63. $block->setRefererUrl($this->_redirect->getRefererUrl());
  64. }
  65. $data = $this->session->getCustomerFormData(true);
  66. $customerId = $this->session->getCustomerId();
  67. $customerDataObject = $this->customerRepository->getById($customerId);
  68. if (!empty($data)) {
  69. $this->dataObjectHelper->populateWithArray(
  70. $customerDataObject,
  71. $data,
  72. \Magento\Customer\Api\Data\CustomerInterface::class
  73. );
  74. }
  75. $this->session->setCustomerData($customerDataObject);
  76. $this->session->setChangePassword($this->getRequest()->getParam('changepass') == 1);
  77. $resultPage->getConfig()->getTitle()->set(__('Account Information'));
  78. return $resultPage;
  79. }
  80. }