CurrentCustomerAddress.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Helper\Session;
  7. use Magento\Customer\Api\AccountManagementInterface;
  8. use Magento\Customer\Api\Data\AddressInterface;
  9. /**
  10. * Class CurrentCustomerAddress
  11. */
  12. class CurrentCustomerAddress
  13. {
  14. /**
  15. * @var \Magento\Customer\Helper\Session\CurrentCustomer
  16. */
  17. protected $currentCustomer;
  18. /**
  19. * @var AccountManagementInterface
  20. */
  21. protected $accountManagement;
  22. /**
  23. * @param CurrentCustomer $currentCustomer
  24. * @param AccountManagementInterface $accountManagement
  25. */
  26. public function __construct(
  27. CurrentCustomer $currentCustomer,
  28. AccountManagementInterface $accountManagement
  29. ) {
  30. $this->currentCustomer = $currentCustomer;
  31. $this->accountManagement = $accountManagement;
  32. }
  33. /**
  34. * Returns default billing address form current customer
  35. *
  36. * @return AddressInterface|null
  37. */
  38. public function getDefaultBillingAddress()
  39. {
  40. return $this->accountManagement->getDefaultBillingAddress($this->currentCustomer->getCustomerId());
  41. }
  42. /**
  43. * Returns default shipping address for current customer
  44. *
  45. * @return AddressInterface|null
  46. */
  47. public function getDefaultShippingAddress()
  48. {
  49. return $this->accountManagement->getDefaultShippingAddress(
  50. $this->currentCustomer->getCustomerId()
  51. );
  52. }
  53. }