Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Index.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
11 
15 class Index extends \Magento\Customer\Controller\Address implements HttpGetActionInterface
16 {
21 
37  public function __construct(
38  \Magento\Framework\App\Action\Context $context,
39  \Magento\Customer\Model\Session $customerSession,
40  \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
41  \Magento\Customer\Model\Metadata\FormFactory $formFactory,
43  \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory,
44  \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory,
45  \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor,
47  \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
48  \Magento\Framework\View\Result\PageFactory $resultPageFactory,
50  ) {
51  $this->customerRepository = $customerRepository;
52  parent::__construct(
53  $context,
54  $customerSession,
55  $formKeyValidator,
56  $formFactory,
60  $dataProcessor,
64  );
65  }
66 
72  public function execute()
73  {
74  $addresses = $this->customerRepository->getById($this->_getSession()->getCustomerId())->getAddresses();
75  if (count($addresses)) {
77  $resultPage = $this->resultPageFactory->create();
78  $block = $resultPage->getLayout()->getBlock('address_book');
79  if ($block) {
80  $block->setRefererUrl($this->_redirect->getRefererUrl());
81  }
82  return $resultPage;
83  } else {
84  return $this->resultRedirectFactory->create()->setPath('*/*/new');
85  }
86  }
87 }
$addressRepository
_redirect($path, $arguments=[])
Definition: Action.php:167
$addresses
Definition: address_list.php:7
$block
Definition: block.php:8
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Magento\Customer\Model\Metadata\FormFactory $formFactory, \Magento\Customer\Api\AddressRepositoryInterface $addressRepository, \Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory, \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory, \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, CustomerRepositoryInterface $customerRepository)
Definition: Index.php:37