10
10
use Magento \Customer \Api \CustomerRepositoryInterface ;
11
11
use Magento \Customer \Api \Data \CustomerInterface ;
12
12
use Magento \Customer \Model \Config \Share ;
13
- use Magento \Framework \App \ObjectManager ;
14
13
use Magento \Framework \App \RequestInterface ;
15
14
use Magento \Framework \Data \OptionSourceInterface ;
16
15
use Magento \Framework \Escaper ;
17
- use Magento \Sales \Api \CreditmemoRepositoryInterface ;
18
- use Magento \Sales \Api \InvoiceRepositoryInterface ;
19
- use Magento \Sales \Api \OrderRepositoryInterface ;
20
- use Magento \Sales \Api \ShipmentRepositoryInterface ;
21
16
use Magento \Store \Model \Group ;
22
17
use Magento \Store \Model \System \Store as SystemStore ;
23
18
use Magento \Store \Model \Website ;
@@ -57,61 +52,25 @@ class Options implements OptionSourceInterface
57
52
*/
58
53
private $ options ;
59
54
60
- /**
61
- * @var OrderRepositoryInterface
62
- */
63
- private $ orderRepository ;
64
-
65
- /**
66
- * @var InvoiceRepositoryInterface
67
- */
68
- private $ invoiceRepository ;
69
-
70
- /**
71
- * @var ShipmentRepositoryInterface
72
- */
73
- private $ shipmentRepository ;
74
-
75
- /**
76
- * @var CreditmemoRepositoryInterface
77
- */
78
- private $ creditmemoRepository ;
79
-
80
55
/**
81
56
* @param CustomerRepositoryInterface $customerRepository
82
57
* @param Escaper $escaper
83
58
* @param RequestInterface $request
84
59
* @param Share $share
85
60
* @param SystemStore $systemStore
86
- * @param OrderRepositoryInterface|null $orderRepository
87
- * @param InvoiceRepositoryInterface|null $invoiceRepository
88
- * @param ShipmentRepositoryInterface|null $shipmentRepository
89
- * @param CreditmemoRepositoryInterface|null $creditmemoRepository
90
61
*/
91
62
public function __construct (
92
63
CustomerRepositoryInterface $ customerRepository ,
93
64
Escaper $ escaper ,
94
65
RequestInterface $ request ,
95
66
Share $ share ,
96
- SystemStore $ systemStore ,
97
- ?OrderRepositoryInterface $ orderRepository = null ,
98
- ?InvoiceRepositoryInterface $ invoiceRepository = null ,
99
- ?ShipmentRepositoryInterface $ shipmentRepository = null ,
100
- ?CreditmemoRepositoryInterface $ creditmemoRepository = null
67
+ SystemStore $ systemStore
101
68
) {
102
69
$ this ->customerRepository = $ customerRepository ;
103
70
$ this ->escaper = $ escaper ;
104
71
$ this ->request = $ request ;
105
72
$ this ->share = $ share ;
106
73
$ this ->systemStore = $ systemStore ;
107
- $ this ->orderRepository = $ orderRepository
108
- ?? ObjectManager::getInstance ()->get (OrderRepositoryInterface::class);
109
- $ this ->invoiceRepository = $ invoiceRepository
110
- ?? ObjectManager::getInstance ()->get (InvoiceRepositoryInterface::class);
111
- $ this ->shipmentRepository = $ shipmentRepository
112
- ?? ObjectManager::getInstance ()->get (ShipmentRepositoryInterface::class);
113
- $ this ->creditmemoRepository = $ creditmemoRepository
114
- ?? ObjectManager::getInstance ()->get (CreditmemoRepositoryInterface::class);
115
74
}
116
75
117
76
/**
@@ -123,7 +82,7 @@ public function toOptionArray(): array
123
82
return $ this ->options ;
124
83
}
125
84
126
- $ customerId = $ this ->getCustomerId ( );
85
+ $ customerId = ( int ) $ this ->request -> getParam ( ' id ' );
127
86
$ this ->options = $ this ->generateCurrentOptions ($ customerId );
128
87
129
88
return $ this ->options ;
@@ -208,30 +167,4 @@ private function fillStoreGroupOptions(Website $website, CustomerInterface $cust
208
167
209
168
return $ groups ;
210
169
}
211
-
212
- /**
213
- * Get Customer id from request param.
214
- *
215
- * @return int
216
- */
217
- private function getCustomerId (): int
218
- {
219
- $ customerId = $ this ->request ->getParam ('id ' );
220
- if (!$ customerId ) {
221
- $ orderId = $ this ->request ->getParam ('order_id ' );
222
- $ shipmentId = $ this ->request ->getParam ('shipment_id ' );
223
- $ creditmemoId = $ this ->request ->getParam ('creditmemo_id ' );
224
- $ invoiceId = $ this ->request ->getParam ('invoice_id ' );
225
- if ($ invoiceId ) {
226
- $ orderId = $ this ->invoiceRepository ->get ($ invoiceId )->getOrderId ();
227
- } elseif ($ shipmentId ) {
228
- $ orderId = $ this ->shipmentRepository ->get ($ shipmentId )->getOrderId ();
229
- } elseif ($ creditmemoId ) {
230
- $ orderId = $ this ->creditmemoRepository ->get ($ creditmemoId )->getOrderId ();
231
- }
232
- $ customerId = $ this ->orderRepository ->get ($ orderId )->getCustomerId ();
233
- }
234
-
235
- return (int )$ customerId ;
236
- }
237
170
}
0 commit comments