Skip to content

Commit d617c3c

Browse files
author
Oleksii Lisovyi
committed
Sales - fix displaying available allowed countries while editing order address in Admin panel
1 parent 7cf99d1 commit d617c3c

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

Diff for: app/code/Magento/Sales/Block/Adminhtml/Order/Address/Form.php

+8
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,12 @@ public function getFormValues()
136136
{
137137
return $this->_getAddress()->getData();
138138
}
139+
140+
/**
141+
* @inheritDoc
142+
*/
143+
protected function getAddressStoreId()
144+
{
145+
return $this->_getAddress()->getOrder()->getStoreId();
146+
}
139147
}

Diff for: app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php

+22-9
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,24 @@ protected function _prepareForm()
271271

272272
$this->_form->setValues($this->getFormValues());
273273

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) {
278282
if ($country['value'] == $countryId) {
279-
$this->_form->getElement('country_id')->setValue($countryId);
283+
$countryElement->setValue($countryId);
280284
}
281285
}
282286
}
283-
if ($this->_form->getElement('country_id')->getValue() === null) {
284-
$this->_form->getElement('country_id')->setValue(
287+
if ($countryElement->getValue() === null) {
288+
$countryElement->setValue(
285289
$this->directoryHelper->getDefaultCountry($this->getStore())
286290
);
287291
}
288-
$this->processCountryOptions($this->_form->getElement('country_id'));
289292
// Set custom renderer for VAT field if needed
290293
$vatIdElement = $this->_form->getElement('vat_id');
291294
if ($vatIdElement && $this->getDisplayVatValidationButton() !== false) {
@@ -309,7 +312,7 @@ protected function _prepareForm()
309312
*/
310313
private function processCountryOptions(\Magento\Framework\Data\Form\Element\AbstractElement $countryElement)
311314
{
312-
$storeId = $this->getBackendQuoteSession()->getStoreId();
315+
$storeId = $this->getAddressStoreId();
313316
$options = $this->getCountriesCollection()
314317
->loadByStore($storeId)
315318
->toOptionArray();
@@ -388,4 +391,14 @@ public function getAddressAsString(\Magento\Customer\Api\Data\AddressInterface $
388391

389392
return $this->escapeHtml($result);
390393
}
394+
395+
/**
396+
* Return address store id.
397+
*
398+
* @return int
399+
*/
400+
protected function getAddressStoreId()
401+
{
402+
return $this->getBackendQuoteSession()->getStoreId();
403+
}
391404
}

0 commit comments

Comments
 (0)