@@ -106,7 +106,6 @@ protected function _extractAddress()
106
106
array_merge ($ existingAddressData , $ attributeValues ),
107
107
'\Magento\Customer\Api\Data\AddressInterface '
108
108
);
109
-
110
109
$ addressDataObject ->setCustomerId ($ this ->_getSession ()->getCustomerId ())
111
110
->setIsDefaultBilling ($ this ->getRequest ()->getParam ('default_billing ' , false ))
112
111
->setIsDefaultShipping ($ this ->getRequest ()->getParam ('default_shipping ' , false ));
@@ -118,12 +117,16 @@ protected function _extractAddress()
118
117
* Retrieve existing address data
119
118
*
120
119
* @return array
120
+ * @throws \Exception
121
121
*/
122
122
protected function getExistingAddressData ()
123
123
{
124
124
$ existingAddressData = [];
125
125
if ($ addressId = $ this ->getRequest ()->getParam ('id ' )) {
126
126
$ existingAddress = $ this ->_addressRepository ->getById ($ addressId );
127
+ if ($ existingAddress ->getCustomerId () !== $ this ->_getSession ()->getCustomerId ()) {
128
+ throw new \Exception ();
129
+ }
127
130
$ existingAddressData = $ this ->_dataProcessor ->buildOutputDataArray (
128
131
$ existingAddress ,
129
132
'\Magento\Customer\Api\Data\AddressInterface '
@@ -175,6 +178,7 @@ protected function updateRegionData(&$attributeValues)
175
178
*/
176
179
public function execute ()
177
180
{
181
+ $ redirectUrl = null ;
178
182
if (!$ this ->_formKeyValidator ->validate ($ this ->getRequest ())) {
179
183
return $ this ->resultRedirectFactory ->create ()->setPath ('*/*/ ' );
180
184
}
@@ -198,11 +202,16 @@ public function execute()
198
202
$ this ->messageManager ->addError ($ error ->getMessage ());
199
203
}
200
204
} catch (\Exception $ e ) {
205
+ $ redirectUrl = $ this ->_buildUrl ('*/*/index ' );
201
206
$ this ->messageManager ->addException ($ e , __ ('We can \'t save the address. ' ));
202
207
}
203
208
204
- $ this ->_getSession ()->setAddressFormData ($ this ->getRequest ()->getPostValue ());
205
- $ url = $ this ->_buildUrl ('*/*/edit ' , ['id ' => $ this ->getRequest ()->getParam ('id ' )]);
209
+ $ url = $ redirectUrl ;
210
+ if (!$ redirectUrl ) {
211
+ $ this ->_getSession ()->setAddressFormData ($ this ->getRequest ()->getPostValue ());
212
+ $ url = $ this ->_buildUrl ('*/*/edit ' , ['id ' => $ this ->getRequest ()->getParam ('id ' )]);
213
+ }
214
+
206
215
return $ this ->resultRedirectFactory ->create ()->setUrl ($ this ->_redirect ->error ($ url ));
207
216
}
208
217
}
0 commit comments