Skip to content

Commit 23efa60

Browse files
committed
FR#StateNotDisplayedSalesAdminAddress Save region correctly to save sales address from admin
1 parent ea35a09 commit 23efa60

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-1
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/AddressSave.php

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
78
namespace Magento\Sales\Controller\Adminhtml\Order;
89

9-
class AddressSave extends \Magento\Sales\Controller\Adminhtml\Order
10+
use Magento\Sales\Controller\Adminhtml\Order;
11+
use Magento\Backend\App\Action;
12+
use Magento\Sales\Api\OrderManagementInterface;
13+
use Magento\Sales\Api\OrderRepositoryInterface;
14+
use Magento\Directory\Model\RegionFactory;
15+
use Psr\Log\LoggerInterface;
16+
use Magento\Framework;
17+
18+
class AddressSave extends Order
1019
{
1120
/**
1221
* Authorization level of a basic admin session
@@ -15,6 +24,57 @@ class AddressSave extends \Magento\Sales\Controller\Adminhtml\Order
1524
*/
1625
const ADMIN_RESOURCE = 'Magento_Sales::actions_edit';
1726

27+
/**
28+
* @var RegionFactory
29+
*/
30+
private $regionFactory;
31+
32+
/**
33+
* @param Action\Context $context
34+
* @param Framework\Registry $coreRegistry
35+
* @param Framework\App\Response\Http\FileFactory $fileFactory
36+
* @param Framework\Translate\InlineInterface $translateInline
37+
* @param Framework\View\Result\PageFactory $resultPageFactory
38+
* @param Framework\Controller\Result\JsonFactory $resultJsonFactory
39+
* @param Framework\View\Result\LayoutFactory $resultLayoutFactory
40+
* @param Framework\Controller\Result\RawFactory $resultRawFactory
41+
* @param OrderManagementInterface $orderManagement
42+
* @param OrderRepositoryInterface $orderRepository
43+
* @param LoggerInterface $logger
44+
* @param RegionFactory $regionFactory
45+
*
46+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
47+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
48+
*/
49+
public function __construct(
50+
Action\Context $context,
51+
Framework\Registry $coreRegistry,
52+
Framework\App\Response\Http\FileFactory $fileFactory,
53+
Framework\Translate\InlineInterface $translateInline,
54+
Framework\View\Result\PageFactory $resultPageFactory,
55+
Framework\Controller\Result\JsonFactory $resultJsonFactory,
56+
Framework\View\Result\LayoutFactory $resultLayoutFactory,
57+
Framework\Controller\Result\RawFactory $resultRawFactory,
58+
OrderManagementInterface $orderManagement,
59+
OrderRepositoryInterface $orderRepository,
60+
LoggerInterface $logger,
61+
RegionFactory $regionFactory
62+
) {
63+
$this->_coreRegistry = $coreRegistry;
64+
$this->_fileFactory = $fileFactory;
65+
$this->_translateInline = $translateInline;
66+
$this->resultPageFactory = $resultPageFactory;
67+
$this->resultJsonFactory = $resultJsonFactory;
68+
$this->resultLayoutFactory = $resultLayoutFactory;
69+
$this->resultRawFactory = $resultRawFactory;
70+
$this->orderManagement = $orderManagement;
71+
$this->orderRepository = $orderRepository;
72+
$this->logger = $logger;
73+
$this->regionFactory = $regionFactory;
74+
parent::__construct($context, $coreRegistry, $fileFactory, $translateInline, $resultPageFactory,
75+
$resultJsonFactory, $resultLayoutFactory, $resultRawFactory, $orderManagement, $orderRepository, $logger);
76+
}
77+
1878
/**
1979
* Save order address
2080
*
@@ -28,6 +88,7 @@ public function execute()
2888
\Magento\Sales\Api\Data\OrderAddressInterface::class
2989
)->load($addressId);
3090
$data = $this->getRequest()->getPostValue();
91+
$this->updateRegionData($data);
3192
$resultRedirect = $this->resultRedirectFactory->create();
3293
if ($data && $address->getId()) {
3394
$address->addData($data);
@@ -51,4 +112,20 @@ public function execute()
51112
return $resultRedirect->setPath('sales/*/');
52113
}
53114
}
115+
116+
/**
117+
* Update region data
118+
*
119+
* @param array $attributeValues
120+
* @return void
121+
* @SuppressWarnings(PHPMD.NPathComplexity)
122+
*/
123+
protected function updateRegionData(&$attributeValues)
124+
{
125+
if (!empty($attributeValues['region_id'])) {
126+
$newRegion = $this->regionFactory->create()->load($attributeValues['region_id']);
127+
$attributeValues['region_code'] = $newRegion->getCode();
128+
$attributeValues['region'] = $newRegion->getDefaultName();
129+
}
130+
}
54131
}

0 commit comments

Comments
 (0)