Skip to content

Commit 832bb38

Browse files
MAGETWO-85305: 12560: Back-End issue for multi-store website: when editing Order shipping/billing address - allowed countries are selected from wrong Store View #982
2 parents d381176 + 5ff7c71 commit 832bb38

File tree

3 files changed

+117
-3
lines changed

3 files changed

+117
-3
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,20 @@ public function getFormValues()
135135
{
136136
return $this->_getAddress()->getData();
137137
}
138+
139+
/**
140+
* @inheritdoc
141+
*/
142+
protected function processCountryOptions(
143+
\Magento\Framework\Data\Form\Element\AbstractElement $countryElement,
144+
$storeId = null
145+
) {
146+
/** @var \Magento\Sales\Model\Order\Address $address */
147+
$address = $this->_coreRegistry->registry('order_address');
148+
if ($address !== null) {
149+
$storeId = $address->getOrder()->getStoreId();
150+
}
151+
152+
parent::processCountryOptions($countryElement, $storeId);
153+
}
138154
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,17 @@ protected function _prepareForm()
293293

294294
/**
295295
* @param \Magento\Framework\Data\Form\Element\AbstractElement $countryElement
296+
* @param string|int $storeId
297+
*
296298
* @return void
297299
*/
298-
private function processCountryOptions(\Magento\Framework\Data\Form\Element\AbstractElement $countryElement)
299-
{
300-
$storeId = $this->getBackendQuoteSession()->getStoreId();
300+
protected function processCountryOptions(
301+
\Magento\Framework\Data\Form\Element\AbstractElement $countryElement,
302+
$storeId = null
303+
) {
304+
if ($storeId === null) {
305+
$storeId = $this->getBackendQuoteSession()->getStoreId();
306+
}
301307
$options = $this->getCountriesCollection()
302308
->loadByStore($storeId)
303309
->toOptionArray();
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Test\Unit\Block\Adminhtml\Order\Address;
8+
9+
/**
10+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
11+
*/
12+
class FormTest extends \PHPUnit\Framework\TestCase
13+
{
14+
/**
15+
* @var \Magento\Sales\Block\Adminhtml\Order\Address\Form
16+
*/
17+
private $addressBlock;
18+
19+
/**
20+
* @var \PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
private $formFactoryMock;
23+
24+
/**
25+
* @var \PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $customerFormFactoryMock;
28+
29+
/**
30+
* @var \PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
private $coreRegistryMock;
33+
34+
/**
35+
* @var \PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
private $countriesCollection;
38+
39+
protected function setUp()
40+
{
41+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
42+
43+
$this->formFactoryMock = $this->createMock(\Magento\Framework\Data\FormFactory::class);
44+
$this->customerFormFactoryMock = $this->createMock(\Magento\Customer\Model\Metadata\FormFactory::class);
45+
$this->coreRegistryMock = $this->createMock(\Magento\Framework\Registry::class);
46+
$this->countriesCollection = $this->createMock(
47+
\Magento\Directory\Model\ResourceModel\Country\Collection::class
48+
);
49+
50+
$this->addressBlock = $objectManager->getObject(
51+
\Magento\Sales\Block\Adminhtml\Order\Address\Form::class,
52+
[
53+
'_formFactory' => $this->formFactoryMock,
54+
'_customerFormFactory' => $this->customerFormFactoryMock,
55+
'_coreRegistry' => $this->coreRegistryMock,
56+
'countriesCollection' => $this->countriesCollection,
57+
]
58+
);
59+
}
60+
61+
public function testGetForm()
62+
{
63+
$formMock = $this->createMock(\Magento\Framework\Data\Form::class);
64+
$fieldsetMock = $this->createMock(\Magento\Framework\Data\Form\Element\Fieldset::class);
65+
$addressFormMock = $this->createMock(\Magento\Customer\Model\Metadata\Form::class);
66+
$addressMock = $this->createMock(\Magento\Sales\Model\Order\Address::class);
67+
$selectMock = $this->createMock(\Magento\Framework\Data\Form\Element\Select::class);
68+
$orderMock = $this->createMock(\Magento\Sales\Model\Order::class);
69+
70+
$this->formFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($formMock);
71+
$formMock->expects($this->atLeastOnce())->method('addFieldset')->willReturn($fieldsetMock);
72+
$this->customerFormFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($addressFormMock);
73+
$addressFormMock->expects($this->atLeastOnce())->method('getAttributes')->willReturn([]);
74+
$this->coreRegistryMock->expects($this->atLeastOnce())->method('registry')->willReturn($addressMock);
75+
$formMock->expects($this->atLeastOnce())->method('getElement')->willReturnOnConsecutiveCalls(
76+
$selectMock,
77+
$selectMock,
78+
$selectMock,
79+
$selectMock,
80+
$selectMock,
81+
$selectMock,
82+
$selectMock,
83+
null
84+
);
85+
$addressMock->expects($this->once())->method('getOrder')->willReturn($orderMock);
86+
$orderMock->expects($this->once())->method('getStoreId')->willReturn(5);
87+
$this->countriesCollection->expects($this->atLeastOnce())->method('loadByStore')
88+
->willReturn($this->countriesCollection);
89+
90+
$this->addressBlock->getForm();
91+
}
92+
}

0 commit comments

Comments
 (0)