4
4
* Copyright © Magento, Inc. All rights reserved.
5
5
* See COPYING.txt for license details.
6
6
*/
7
+
7
8
namespace Magento \Sales \Controller \Adminhtml \Order ;
8
9
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
10
19
{
11
20
/**
12
21
* Authorization level of a basic admin session
@@ -15,6 +24,57 @@ class AddressSave extends \Magento\Sales\Controller\Adminhtml\Order
15
24
*/
16
25
const ADMIN_RESOURCE = 'Magento_Sales::actions_edit ' ;
17
26
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
+
18
78
/**
19
79
* Save order address
20
80
*
@@ -28,6 +88,7 @@ public function execute()
28
88
\Magento \Sales \Api \Data \OrderAddressInterface::class
29
89
)->load ($ addressId );
30
90
$ data = $ this ->getRequest ()->getPostValue ();
91
+ $ this ->updateRegionData ($ data );
31
92
$ resultRedirect = $ this ->resultRedirectFactory ->create ();
32
93
if ($ data && $ address ->getId ()) {
33
94
$ address ->addData ($ data );
@@ -51,4 +112,20 @@ public function execute()
51
112
return $ resultRedirect ->setPath ('sales/*/ ' );
52
113
}
53
114
}
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
+ }
54
131
}
0 commit comments