Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/code/Magento/Sales/Block/Adminhtml/Order/Address/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,12 @@ public function getFormValues()
{
return $this->_getAddress()->getData();
}

/**
* @inheritDoc
*/
protected function getAddressStoreId()
{
return $this->_getAddress()->getOrder()->getStoreId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,24 @@ protected function _prepareForm()

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

if ($this->_form->getElement('country_id')->getValue()) {
$countryId = $this->_form->getElement('country_id')->getValue();
$this->_form->getElement('country_id')->setValue(null);
foreach ($this->_form->getElement('country_id')->getValues() as $country) {
$countryElement = $this->_form->getElement('country_id');

$this->processCountryOptions($countryElement);

if ($countryElement->getValue()) {
$countryId = $countryElement->getValue();
$countryElement->setValue(null);
foreach ($countryElement->getValues() as $country) {
if ($country['value'] == $countryId) {
$this->_form->getElement('country_id')->setValue($countryId);
$countryElement->setValue($countryId);
}
}
}
if ($this->_form->getElement('country_id')->getValue() === null) {
$this->_form->getElement('country_id')->setValue(
if ($countryElement->getValue() === null) {
$countryElement->setValue(
$this->directoryHelper->getDefaultCountry($this->getStore())
);
}
$this->processCountryOptions($this->_form->getElement('country_id'));
// Set custom renderer for VAT field if needed
$vatIdElement = $this->_form->getElement('vat_id');
if ($vatIdElement && $this->getDisplayVatValidationButton() !== false) {
Expand All @@ -309,7 +312,7 @@ protected function _prepareForm()
*/
private function processCountryOptions(\Magento\Framework\Data\Form\Element\AbstractElement $countryElement)
{
$storeId = $this->getBackendQuoteSession()->getStoreId();
$storeId = $this->getAddressStoreId();
$options = $this->getCountriesCollection()
->loadByStore($storeId)
->toOptionArray();
Expand Down Expand Up @@ -388,4 +391,14 @@ public function getAddressAsString(\Magento\Customer\Api\Data\AddressInterface $

return $this->escapeHtml($result);
}

/**
* Return address store id.
*
* @return int
*/
protected function getAddressStoreId()
{
return $this->getBackendQuoteSession()->getStoreId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ protected function setUp()
'_orderCreate' => $this->orderCreate
]
);

// Do not display VAT validation button on edit order address form
// Emulate fix done in controller
/** @see \Magento\Sales\Controller\Adminhtml\Order\Address::execute */
$this->addressBlock->setDisplayVatValidationButton(false);
}

public function testGetForm()
Expand Down