5
5
*/
6
6
namespace Magento \Customer \Controller \Adminhtml \Index ;
7
7
8
+ use Magento \Customer \Api \AccountManagementInterface ;
9
+ use Magento \Customer \Api \AddressRepositoryInterface ;
10
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
11
+ use Magento \Customer \Model \Address \Mapper ;
12
+ use Magento \Customer \Model \AddressRegistry ;
13
+ use Magento \Framework \Api \DataObjectHelper ;
14
+ use Magento \Customer \Api \Data \AddressInterfaceFactory ;
15
+ use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
16
+ use Magento \Framework \DataObjectFactory as ObjectFactory ;
8
17
use Magento \Framework \App \Action \HttpPostActionInterface as HttpPostActionInterface ;
9
18
use Magento \Customer \Api \AddressMetadataInterface ;
10
19
use Magento \Customer \Api \CustomerMetadataInterface ;
13
22
use Magento \Customer \Model \EmailNotificationInterface ;
14
23
use Magento \Customer \Model \Metadata \Form ;
15
24
use Magento \Framework \Exception \LocalizedException ;
25
+ use Magento \Framework \Exception \NoSuchEntityException ;
26
+ use Magento \Framework \App \ObjectManager ;
16
27
17
28
/**
18
29
* Save customer action.
@@ -26,6 +37,100 @@ class Save extends \Magento\Customer\Controller\Adminhtml\Index implements HttpP
26
37
*/
27
38
private $ emailNotification ;
28
39
40
+ /**
41
+ * @var AddressRegistry
42
+ */
43
+ private $ addressRegistry ;
44
+
45
+ /**
46
+ * Constructor
47
+ *
48
+ * @param \Magento\Backend\App\Action\Context $context
49
+ * @param \Magento\Framework\Registry $coreRegistry
50
+ * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
51
+ * @param \Magento\Customer\Model\CustomerFactory $customerFactory
52
+ * @param \Magento\Customer\Model\AddressFactory $addressFactory
53
+ * @param \Magento\Customer\Model\Metadata\FormFactory $formFactory
54
+ * @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory
55
+ * @param \Magento\Customer\Helper\View $viewHelper
56
+ * @param \Magento\Framework\Math\Random $random
57
+ * @param CustomerRepositoryInterface $customerRepository
58
+ * @param \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter
59
+ * @param Mapper $addressMapper
60
+ * @param AccountManagementInterface $customerAccountManagement
61
+ * @param AddressRepositoryInterface $addressRepository
62
+ * @param CustomerInterfaceFactory $customerDataFactory
63
+ * @param AddressInterfaceFactory $addressDataFactory
64
+ * @param \Magento\Customer\Model\Customer\Mapper $customerMapper
65
+ * @param \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor
66
+ * @param DataObjectHelper $dataObjectHelper
67
+ * @param ObjectFactory $objectFactory
68
+ * @param \Magento\Framework\View\LayoutFactory $layoutFactory
69
+ * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
70
+ * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
71
+ * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
72
+ * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
73
+ * @param AddressRegistry|null $addressRegistry
74
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
75
+ */
76
+ public function __construct (
77
+ \Magento \Backend \App \Action \Context $ context ,
78
+ \Magento \Framework \Registry $ coreRegistry ,
79
+ \Magento \Framework \App \Response \Http \FileFactory $ fileFactory ,
80
+ \Magento \Customer \Model \CustomerFactory $ customerFactory ,
81
+ \Magento \Customer \Model \AddressFactory $ addressFactory ,
82
+ \Magento \Customer \Model \Metadata \FormFactory $ formFactory ,
83
+ \Magento \Newsletter \Model \SubscriberFactory $ subscriberFactory ,
84
+ \Magento \Customer \Helper \View $ viewHelper ,
85
+ \Magento \Framework \Math \Random $ random ,
86
+ CustomerRepositoryInterface $ customerRepository ,
87
+ \Magento \Framework \Api \ExtensibleDataObjectConverter $ extensibleDataObjectConverter ,
88
+ Mapper $ addressMapper ,
89
+ AccountManagementInterface $ customerAccountManagement ,
90
+ AddressRepositoryInterface $ addressRepository ,
91
+ CustomerInterfaceFactory $ customerDataFactory ,
92
+ AddressInterfaceFactory $ addressDataFactory ,
93
+ \Magento \Customer \Model \Customer \Mapper $ customerMapper ,
94
+ \Magento \Framework \Reflection \DataObjectProcessor $ dataObjectProcessor ,
95
+ DataObjectHelper $ dataObjectHelper ,
96
+ ObjectFactory $ objectFactory ,
97
+ \Magento \Framework \View \LayoutFactory $ layoutFactory ,
98
+ \Magento \Framework \View \Result \LayoutFactory $ resultLayoutFactory ,
99
+ \Magento \Framework \View \Result \PageFactory $ resultPageFactory ,
100
+ \Magento \Backend \Model \View \Result \ForwardFactory $ resultForwardFactory ,
101
+ \Magento \Framework \Controller \Result \JsonFactory $ resultJsonFactory ,
102
+ AddressRegistry $ addressRegistry = null
103
+ ) {
104
+ parent ::__construct (
105
+ $ context ,
106
+ $ coreRegistry ,
107
+ $ fileFactory ,
108
+ $ customerFactory ,
109
+ $ addressFactory ,
110
+ $ formFactory ,
111
+ $ subscriberFactory ,
112
+ $ viewHelper ,
113
+ $ random ,
114
+ $ customerRepository ,
115
+ $ extensibleDataObjectConverter ,
116
+ $ addressMapper ,
117
+ $ customerAccountManagement ,
118
+ $ addressRepository ,
119
+ $ customerDataFactory ,
120
+ $ addressDataFactory ,
121
+ $ customerMapper ,
122
+ $ dataObjectProcessor ,
123
+ $ dataObjectHelper ,
124
+ $ objectFactory ,
125
+ $ layoutFactory ,
126
+ $ resultLayoutFactory ,
127
+ $ resultPageFactory ,
128
+ $ resultForwardFactory ,
129
+ $ resultJsonFactory
130
+ );
131
+ $ this ->addressRegistry = $ addressRegistry ?: ObjectManager::getInstance ()->get (AddressRegistry::class);
132
+ }
133
+
29
134
/**
30
135
* Reformat customer account data to be compatible with customer service interface
31
136
*
@@ -195,6 +300,8 @@ public function execute()
195
300
196
301
if ($ customerId ) {
197
302
$ currentCustomer = $ this ->_customerRepository ->getById ($ customerId );
303
+ // No need to validate customer address while editing customer profile
304
+ $ this ->disableAddressValidation ($ currentCustomer );
198
305
$ customerData = array_merge (
199
306
$ this ->customerMapper ->toFlatArray ($ currentCustomer ),
200
307
$ customerData
@@ -368,4 +475,18 @@ private function getCurrentCustomerId()
368
475
369
476
return $ customerId ;
370
477
}
478
+
479
+ /**
480
+ * Disable Customer Address Validation
481
+ *
482
+ * @param CustomerInterface $customer
483
+ * @throws NoSuchEntityException
484
+ */
485
+ private function disableAddressValidation ($ customer )
486
+ {
487
+ foreach ($ customer ->getAddresses () as $ address ) {
488
+ $ addressModel = $ this ->addressRegistry ->retrieve ($ address ->getId ());
489
+ $ addressModel ->setShouldIgnoreValidation (true );
490
+ }
491
+ }
371
492
}
0 commit comments