Skip to content

Commit 6db35d8

Browse files
author
Gabriel Galvao da Gama
committed
Applied fix for Stores are not shown in Login as Customer
1 parent 1c3fb55 commit 6db35d8

File tree

1 file changed

+69
-2
lines changed
  • app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/ConfirmationPopup

1 file changed

+69
-2
lines changed

app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/ConfirmationPopup/Options.php

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
use Magento\Customer\Api\CustomerRepositoryInterface;
1111
use Magento\Customer\Api\Data\CustomerInterface;
1212
use Magento\Customer\Model\Config\Share;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\App\RequestInterface;
1415
use Magento\Framework\Data\OptionSourceInterface;
1516
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;
1621
use Magento\Store\Model\Group;
1722
use Magento\Store\Model\System\Store as SystemStore;
1823
use Magento\Store\Model\Website;
@@ -52,25 +57,61 @@ class Options implements OptionSourceInterface
5257
*/
5358
private $options;
5459

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+
5580
/**
5681
* @param CustomerRepositoryInterface $customerRepository
5782
* @param Escaper $escaper
5883
* @param RequestInterface $request
5984
* @param Share $share
6085
* @param SystemStore $systemStore
86+
* @param OrderRepositoryInterface|null $orderRepository
87+
* @param InvoiceRepositoryInterface|null $invoiceRepository
88+
* @param ShipmentRepositoryInterface|null $shipmentRepository
89+
* @param CreditmemoRepositoryInterface|null $creditmemoRepository
6190
*/
6291
public function __construct(
6392
CustomerRepositoryInterface $customerRepository,
6493
Escaper $escaper,
6594
RequestInterface $request,
6695
Share $share,
67-
SystemStore $systemStore
96+
SystemStore $systemStore,
97+
?OrderRepositoryInterface $orderRepository = null,
98+
?InvoiceRepositoryInterface $invoiceRepository = null,
99+
?ShipmentRepositoryInterface $shipmentRepository = null,
100+
?CreditmemoRepositoryInterface $creditmemoRepository = null
68101
) {
69102
$this->customerRepository = $customerRepository;
70103
$this->escaper = $escaper;
71104
$this->request = $request;
72105
$this->share = $share;
73106
$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);
74115
}
75116

76117
/**
@@ -82,7 +123,7 @@ public function toOptionArray(): array
82123
return $this->options;
83124
}
84125

85-
$customerId = (int)$this->request->getParam('id');
126+
$customerId = $this->getCustomerId();
86127
$this->options = $this->generateCurrentOptions($customerId);
87128

88129
return $this->options;
@@ -167,4 +208,30 @@ private function fillStoreGroupOptions(Website $website, CustomerInterface $cust
167208

168209
return $groups;
169210
}
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+
}
170237
}

0 commit comments

Comments
 (0)