Persistent.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Persistent\CustomerData;
  8. use Magento\Customer\Api\CustomerRepositoryInterface;
  9. use Magento\Customer\CustomerData\SectionSourceInterface;
  10. use Magento\Customer\Helper\View;
  11. use Magento\Persistent\Helper\Session;
  12. /**
  13. * Customer persistent section
  14. */
  15. class Persistent implements SectionSourceInterface
  16. {
  17. /**
  18. * @var Session
  19. */
  20. private $persistentSession;
  21. /**
  22. * @var View
  23. */
  24. private $customerViewHelper;
  25. /**
  26. * @var CustomerRepositoryInterface
  27. */
  28. private $customerRepository;
  29. /**
  30. * @param Session $persistentSession
  31. * @param View $customerViewHelper
  32. * @param CustomerRepositoryInterface $customerRepository
  33. */
  34. public function __construct(
  35. Session $persistentSession,
  36. View $customerViewHelper,
  37. CustomerRepositoryInterface $customerRepository
  38. ) {
  39. $this->persistentSession = $persistentSession;
  40. $this->customerViewHelper = $customerViewHelper;
  41. $this->customerRepository = $customerRepository;
  42. }
  43. /**
  44. * Get data.
  45. *
  46. * @return array
  47. */
  48. public function getSectionData(): array
  49. {
  50. if (!$this->persistentSession->isPersistent()) {
  51. return [];
  52. }
  53. $customerId = $this->persistentSession->getSession()->getCustomerId();
  54. if (!$customerId) {
  55. return [];
  56. }
  57. $customer = $this->customerRepository->getById($customerId);
  58. return [
  59. 'fullname' => $this->customerViewHelper->getCustomerName($customer),
  60. ];
  61. }
  62. }