Index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Customer\Controller\Address;
  8. use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
  9. use Magento\Customer\Api\CustomerRepositoryInterface;
  10. /**
  11. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  12. */
  13. class Index extends \Magento\Customer\Controller\Address implements HttpGetActionInterface
  14. {
  15. /**
  16. * @var CustomerRepositoryInterface
  17. */
  18. protected $customerRepository;
  19. /**
  20. * @param \Magento\Framework\App\Action\Context $context
  21. * @param \Magento\Customer\Model\Session $customerSession
  22. * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
  23. * @param \Magento\Customer\Model\Metadata\FormFactory $formFactory
  24. * @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
  25. * @param \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory
  26. * @param \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory
  27. * @param \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor
  28. * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
  29. * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory
  30. * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
  31. * @param CustomerRepositoryInterface $customerRepository
  32. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  33. */
  34. public function __construct(
  35. \Magento\Framework\App\Action\Context $context,
  36. \Magento\Customer\Model\Session $customerSession,
  37. \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
  38. \Magento\Customer\Model\Metadata\FormFactory $formFactory,
  39. \Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
  40. \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory,
  41. \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory,
  42. \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor,
  43. \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
  44. \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
  45. \Magento\Framework\View\Result\PageFactory $resultPageFactory,
  46. CustomerRepositoryInterface $customerRepository
  47. ) {
  48. $this->customerRepository = $customerRepository;
  49. parent::__construct(
  50. $context,
  51. $customerSession,
  52. $formKeyValidator,
  53. $formFactory,
  54. $addressRepository,
  55. $addressDataFactory,
  56. $regionDataFactory,
  57. $dataProcessor,
  58. $dataObjectHelper,
  59. $resultForwardFactory,
  60. $resultPageFactory
  61. );
  62. }
  63. /**
  64. * Customer addresses list
  65. *
  66. * @return \Magento\Framework\Controller\ResultInterface
  67. */
  68. public function execute()
  69. {
  70. $addresses = $this->customerRepository->getById($this->_getSession()->getCustomerId())->getAddresses();
  71. if (count($addresses)) {
  72. /** @var \Magento\Framework\View\Result\Page $resultPage */
  73. $resultPage = $this->resultPageFactory->create();
  74. $block = $resultPage->getLayout()->getBlock('address_book');
  75. if ($block) {
  76. $block->setRefererUrl($this->_redirect->getRefererUrl());
  77. }
  78. return $resultPage;
  79. } else {
  80. return $this->resultRedirectFactory->create()->setPath('*/*/new');
  81. }
  82. }
  83. }