@@ -271,21 +271,24 @@ protected function _prepareForm()
271
271
272
272
$ this ->_form ->setValues ($ this ->getFormValues ());
273
273
274
- if ($ this ->_form ->getElement ('country_id ' )->getValue ()) {
275
- $ countryId = $ this ->_form ->getElement ('country_id ' )->getValue ();
276
- $ this ->_form ->getElement ('country_id ' )->setValue (null );
277
- foreach ($ this ->_form ->getElement ('country_id ' )->getValues () as $ country ) {
274
+ $ countryElement = $ this ->_form ->getElement ('country_id ' );
275
+
276
+ $ this ->processCountryOptions ($ countryElement );
277
+
278
+ if ($ countryElement ->getValue ()) {
279
+ $ countryId = $ countryElement ->getValue ();
280
+ $ countryElement ->setValue (null );
281
+ foreach ($ countryElement ->getValues () as $ country ) {
278
282
if ($ country ['value ' ] == $ countryId ) {
279
- $ this -> _form -> getElement ( ' country_id ' ) ->setValue ($ countryId );
283
+ $ countryElement ->setValue ($ countryId );
280
284
}
281
285
}
282
286
}
283
- if ($ this -> _form -> getElement ( ' country_id ' ) ->getValue () === null ) {
284
- $ this -> _form -> getElement ( ' country_id ' ) ->setValue (
287
+ if ($ countryElement ->getValue () === null ) {
288
+ $ countryElement ->setValue (
285
289
$ this ->directoryHelper ->getDefaultCountry ($ this ->getStore ())
286
290
);
287
291
}
288
- $ this ->processCountryOptions ($ this ->_form ->getElement ('country_id ' ));
289
292
// Set custom renderer for VAT field if needed
290
293
$ vatIdElement = $ this ->_form ->getElement ('vat_id ' );
291
294
if ($ vatIdElement && $ this ->getDisplayVatValidationButton () !== false ) {
@@ -309,7 +312,7 @@ protected function _prepareForm()
309
312
*/
310
313
private function processCountryOptions (\Magento \Framework \Data \Form \Element \AbstractElement $ countryElement )
311
314
{
312
- $ storeId = $ this ->getBackendQuoteSession ()-> getStoreId ();
315
+ $ storeId = $ this ->getAddressStoreId ();
313
316
$ options = $ this ->getCountriesCollection ()
314
317
->loadByStore ($ storeId )
315
318
->toOptionArray ();
@@ -388,4 +391,14 @@ public function getAddressAsString(\Magento\Customer\Api\Data\AddressInterface $
388
391
389
392
return $ this ->escapeHtml ($ result );
390
393
}
394
+
395
+ /**
396
+ * Return address store id.
397
+ *
398
+ * @return int
399
+ */
400
+ protected function getAddressStoreId ()
401
+ {
402
+ return $ this ->getBackendQuoteSession ()->getStoreId ();
403
+ }
391
404
}
0 commit comments