Customer.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\CustomerData;
  7. use Magento\Customer\Helper\Session\CurrentCustomer;
  8. use Magento\Customer\Helper\View;
  9. /**
  10. * Customer section
  11. */
  12. class Customer implements SectionSourceInterface
  13. {
  14. /**
  15. * @var CurrentCustomer
  16. */
  17. protected $currentCustomer;
  18. /**
  19. * @var View
  20. */
  21. private $customerViewHelper;
  22. /**
  23. * @param CurrentCustomer $currentCustomer
  24. * @param View $customerViewHelper
  25. */
  26. public function __construct(
  27. CurrentCustomer $currentCustomer,
  28. View $customerViewHelper
  29. ) {
  30. $this->currentCustomer = $currentCustomer;
  31. $this->customerViewHelper = $customerViewHelper;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function getSectionData()
  37. {
  38. if (!$this->currentCustomer->getCustomerId()) {
  39. return [];
  40. }
  41. $customer = $this->currentCustomer->getCustomer();
  42. return [
  43. 'fullname' => $this->customerViewHelper->getCustomerName($customer),
  44. 'firstname' => $customer->getFirstname(),
  45. 'websiteId' => $customer->getWebsiteId(),
  46. ];
  47. }
  48. }