Skip to content

Commit f0219bf

Browse files
ENGCOM-5738: Sales - fix displaying available allowed countries while editing order address in Admin panel #24345
- Merge Pull Request #24345 from oleksii-lisovyi/magento2:fix-availalbe-allowed-countries-for-order-address-in-admin-panel - Merged commits: 1. d617c3c 2. 883d9f5
2 parents 31a6cd7 + 883d9f5 commit f0219bf

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

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

Lines changed: 8 additions & 0 deletions
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
}

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

Lines changed: 22 additions & 9 deletions
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
}

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Address/FormTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ protected function setUp()
9595
'_orderCreate' => $this->orderCreate
9696
]
9797
);
98+
99+
// Do not display VAT validation button on edit order address form
100+
// Emulate fix done in controller
101+
/** @see \Magento\Sales\Controller\Adminhtml\Order\Address::execute */
102+
$this->addressBlock->setDisplayVatValidationButton(false);
98103
}
99104

100105
public function testGetForm()

0 commit comments

Comments
 (0)