1
+ new file mode 100644
2
+ --- /dev/null
3
+ +++ b/vendor/magento/module-company/Model/Customer/AccountManagement/CompanyRequestHydrator.php
4
+ @@ -0,0 +1,66 @@
5
+ + <?php
6
+ + /**
7
+ + * Copyright © Magento, Inc. All rights reserved.
8
+ + * See COPYING.txt for license details.
9
+ + */
10
+ + declare(strict_types=1);
11
+ +
12
+ + namespace Magento\Company\Model\Customer\AccountManagement;
13
+ +
14
+ + use Magento\Company\Api\Data\CompanyInterface;
15
+ +
16
+ + /**
17
+ + * Getting company data form request.
18
+ + */
19
+ + class CompanyRequestHydrator
20
+ + {
21
+ + /**
22
+ + * @var \Magento\Framework\App\Request\Http
23
+ + */
24
+ + private $request;
25
+ + /**
26
+ + * @var array
27
+ + */
28
+ + private $fieldsToSave = [
29
+ + CompanyInterface::NAME,
30
+ + CompanyInterface::LEGAL_NAME,
31
+ + CompanyInterface::COMPANY_EMAIL,
32
+ + CompanyInterface::VAT_TAX_ID,
33
+ + CompanyInterface::RESELLER_ID,
34
+ + CompanyInterface::STREET,
35
+ + CompanyInterface::CITY,
36
+ + CompanyInterface::COUNTRY_ID,
37
+ + CompanyInterface::REGION,
38
+ + CompanyInterface::REGION_ID,
39
+ + CompanyInterface::POSTCODE,
40
+ + CompanyInterface::TELEPHONE,
41
+ + CompanyInterface::JOB_TITLE
42
+ + ];
43
+ +
44
+ + /**
45
+ + * @param \Magento\Framework\App\Request\Http $request
46
+ + */
47
+ + public function __construct(
48
+ + \Magento\Framework\App\Request\Http $request,
49
+ + ) {
50
+ + $this->request = $request;
51
+ + }
52
+ +
53
+ + /**
54
+ + * Get and hydrate company data from HTTP request.
55
+ + *
56
+ + * @return array
57
+ + */
58
+ + public function getCompanyDataFromRequest(): array
59
+ + {
60
+ + $result = [];
61
+ + $companyData = $this->request->getPost('company', []);
62
+ + foreach ($this->fieldsToSave as $item) {
63
+ + if (isset($companyData[$item])) {
64
+ + $result[$item] = $companyData[$item];
65
+ + }
66
+ + }
67
+ +
68
+ + return $result;
69
+ + }
70
+ + }
71
+ --- a/vendor/magento/module-company/Plugin/Customer/Api/AccountManagement.php
72
+ +++ b/vendor/magento/module-company/Plugin/Customer/Api/AccountManagement.php
73
+ @@ -11,17 +11,13 @@
74
+ use Magento\Customer\Api\CustomerRepositoryInterface;
75
+ use Magento\Company\Api\CompanyManagementInterface;
76
+ use Magento\Framework\Exception\NoSuchEntityException;
77
+ + use Magento\Company\Model\Customer\AccountManagement\CompanyRequestHydrator;
78
+
79
+ /**
80
+ * Plugin for AccountManagement. Processing company data.
81
+ */
82
+ class AccountManagement
83
+ {
84
+ - /**
85
+ - * @var \Magento\Framework\App\Request\Http
86
+ - */
87
+ - private $request;
88
+ -
89
+ /**
90
+ * @var \Magento\Company\Model\Email\Sender
91
+ */
92
+ @@ -47,30 +43,35 @@
93
+ */
94
+ private $customerRepository;
95
+
96
+ + /**
97
+ + * @var CompanyRequestHydrator
98
+ + */
99
+ + private $companyRequestHydrator;
100
+ +
101
+ /**
102
+ * AccountManagement constructor
103
+ *
104
+ - * @param \Magento\Framework\App\Request\Http $request
105
+ * @param \Magento\Company\Model\Email\Sender $companyEmailSender
106
+ * @param \Magento\Backend\Model\UrlInterface $urlBuilder
107
+ * @param \Magento\Company\Model\Customer\Company $customerCompany
108
+ * @param CompanyManagementInterface $companyManagement
109
+ * @param CustomerRepositoryInterface $customerRepository
110
+ + * @param CompanyRequestHydrator $companyRequestHydrator
111
+ */
112
+ public function __construct(
113
+ - \Magento\Framework\App\Request\Http $request,
114
+ \Magento\Company\Model\Email\Sender $companyEmailSender,
115
+ \Magento\Backend\Model\UrlInterface $urlBuilder,
116
+ \Magento\Company\Model\Customer\Company $customerCompany,
117
+ CompanyManagementInterface $companyManagement,
118
+ - CustomerRepositoryInterface $customerRepository
119
+ + CustomerRepositoryInterface $customerRepository,
120
+ + CompanyRequestHydrator $companyRequestHydrator
121
+ ) {
122
+ - $this->request = $request;
123
+ $this->companyEmailSender = $companyEmailSender;
124
+ $this->urlBuilder = $urlBuilder;
125
+ $this->customerCompany = $customerCompany;
126
+ $this->companyManagement = $companyManagement;
127
+ $this->customerRepository = $customerRepository;
128
+ + $this->companyRequestHydrator = $companyRequestHydrator;
129
+ }
130
+
131
+ /**
132
+ @@ -127,11 +128,7 @@
133
+ \Magento\Customer\Api\AccountManagementInterface $subject,
134
+ \Magento\Customer\Api\Data\CustomerInterface $result
135
+ ) {
136
+ - $companyData = $this->request->getPost('company', []);
137
+ - if (isset($companyData['status'])) {
138
+ - unset($companyData['status']);
139
+ - }
140
+ -
141
+ + $companyData = $this->companyRequestHydrator->getCompanyDataFromRequest();
142
+ if (is_array($companyData) && !empty($companyData)) {
143
+ $jobTitle = $companyData['job_title'] ?? null;
144
+ $companyDataObject = $this->customerCompany->createCompany($result, $companyData, $jobTitle);
0 commit comments