|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\LoginAsCustomer\CustomerData; |
| 9 | + |
| 10 | +use Magento\Customer\CustomerData\SectionSourceInterface; |
| 11 | +use Magento\Customer\Model\Session; |
| 12 | +use Magento\Store\Model\StoreManagerInterface; |
| 13 | + |
| 14 | +/** |
| 15 | + * Customer data for the logged_as_customer section |
| 16 | + */ |
| 17 | +class LoginAsCustomer implements SectionSourceInterface |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var Session |
| 21 | + */ |
| 22 | + private $customerSession; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var StoreManagerInterface |
| 26 | + */ |
| 27 | + private $storeManager; |
| 28 | + |
| 29 | + /** |
| 30 | + * LoginAsCustomer constructor. |
| 31 | + * @param Session $customerSession |
| 32 | + * @param StoreManagerInterface $storeManager |
| 33 | + */ |
| 34 | + public function __construct( |
| 35 | + Session $customerSession, |
| 36 | + StoreManagerInterface $storeManager |
| 37 | + ) { |
| 38 | + $this->customerSession = $customerSession; |
| 39 | + $this->storeManager = $storeManager; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Retrieve private customer data for the logged_as_customer section |
| 44 | + * @return array |
| 45 | + */ |
| 46 | + public function getSectionData():array |
| 47 | + { |
| 48 | + if (!$this->customerSession->getCustomerId()) { |
| 49 | + return []; |
| 50 | + } |
| 51 | + |
| 52 | + return [ |
| 53 | + 'admin_user_id' => $this->customerSession->getLoggedAsCustomerAdmindId(), |
| 54 | + 'website_name' => $this->storeManager->getWebsite()->getName() |
| 55 | + ]; |
| 56 | + } |
| 57 | +} |
0 commit comments