24
24
use Magento \Framework \View \Result \LayoutFactory ;
25
25
use Magento \Framework \Controller \Result \RawFactory ;
26
26
use Magento \Framework \Exception \LocalizedException ;
27
+ use Magento \Framework \App \ObjectManager ;
27
28
28
29
/**
29
30
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
31
31
*/
32
32
class AddressSave extends Order
33
33
{
@@ -55,8 +55,9 @@ class AddressSave extends Order
55
55
* @param OrderManagementInterface $orderManagement
56
56
* @param OrderRepositoryInterface $orderRepository
57
57
* @param LoggerInterface $logger
58
- * @param RegionFactory $regionFactory
58
+ * @param RegionFactory|null $regionFactory
59
59
*
60
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
60
61
*/
61
62
public function __construct (
62
63
Context $ context ,
@@ -70,9 +71,9 @@ public function __construct(
70
71
OrderManagementInterface $ orderManagement ,
71
72
OrderRepositoryInterface $ orderRepository ,
72
73
LoggerInterface $ logger ,
73
- RegionFactory $ regionFactory
74
+ RegionFactory $ regionFactory = null
74
75
) {
75
- $ this ->regionFactory = $ regionFactory ;
76
+ $ this ->regionFactory = $ regionFactory ?: ObjectManager:: getInstance ()-> get (RegionFactory::class) ;
76
77
parent ::__construct (
77
78
$ context ,
78
79
$ coreRegistry ,
@@ -101,7 +102,7 @@ public function execute()
101
102
OrderAddressInterface::class
102
103
)->load ($ addressId );
103
104
$ data = $ this ->getRequest ()->getPostValue ();
104
- $ this ->updateRegionData ($ data );
105
+ $ data = $ this ->updateRegionData ($ data );
105
106
$ resultRedirect = $ this ->resultRedirectFactory ->create ();
106
107
if ($ data && $ address ->getId ()) {
107
108
$ address ->addData ($ data );
@@ -130,14 +131,15 @@ public function execute()
130
131
* Update region data
131
132
*
132
133
* @param array $attributeValues
133
- * @return void
134
+ * @return array
134
135
*/
135
- protected function updateRegionData (& $ attributeValues )
136
+ protected function updateRegionData ($ attributeValues )
136
137
{
137
138
if (!empty ($ attributeValues ['region_id ' ])) {
138
139
$ newRegion = $ this ->regionFactory ->create ()->load ($ attributeValues ['region_id ' ]);
139
140
$ attributeValues ['region_code ' ] = $ newRegion ->getCode ();
140
141
$ attributeValues ['region ' ] = $ newRegion ->getDefaultName ();
141
142
}
143
+ return $ attributeValues ;
142
144
}
143
145
}
0 commit comments