Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Select.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Customer\Helper\Address as CustomerAddressHelper;
11 
20 {
25 
29  protected $addressMapper;
30 
34  protected $_isScopePrivate = true;
35 
39  protected $filterBuilder;
40 
45 
49  protected $addressRepository;
50 
63  public function __construct(
64  \Magento\Framework\View\Element\Template\Context $context,
65  \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping,
66  CustomerAddressHelper $customerAddressHelper,
67  \Magento\Customer\Model\Address\Mapper $addressMapper,
69  \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
70  \Magento\Framework\Api\FilterBuilder $filterBuilder,
71  array $data = []
72  ) {
73  $this->_customerAddressHelper = $customerAddressHelper;
74  $this->addressMapper = $addressMapper;
75  $this->addressRepository = $addressRepository;
76  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
77  $this->filterBuilder = $filterBuilder;
78  parent::__construct($context, $multishipping, $data);
79  }
80 
84  protected function _prepareLayout()
85  {
86  $this->pageConfig->getTitle()->set(
87  __('Change Billing Address') . ' - ' . $this->pageConfig->getTitle()->getDefault()
88  );
89  return parent::_prepareLayout();
90  }
91 
97  public function getAddress()
98  {
99  $addresses = $this->getData('address_collection');
100  if ($addresses === null) {
101  try {
102  $filter = $this->filterBuilder->setField('parent_id')
103  ->setValue($this->_multishipping->getCustomer()->getId())
104  ->setConditionType('eq')
105  ->create();
106  $addresses = (array)($this->addressRepository->getList(
107  $this->searchCriteriaBuilder->addFilters([$filter])->create()
108  )->getItems());
109  } catch (NoSuchEntityException $e) {
110  return [];
111  }
112  $this->setData('address_collection', $addresses);
113  }
114  return $addresses;
115  }
116 
123  public function getAddressAsHtml(\Magento\Customer\Api\Data\AddressInterface $address)
124  {
125  $formatTypeRenderer = $this->_customerAddressHelper->getFormatTypeRenderer('html');
126  $result = '';
127  if ($formatTypeRenderer) {
128  $result = $formatTypeRenderer->renderArray($this->addressMapper->toFlatArray($address));
129  }
130  return $result;
131  }
132 
139  public function isAddressDefaultBilling(\Magento\Customer\Api\Data\AddressInterface $address)
140  {
141  return $address->getId() == $this->_multishipping->getCustomer()->getDefaultBilling();
142  }
143 
150  public function isAddressDefaultShipping(\Magento\Customer\Api\Data\AddressInterface $address)
151  {
152  return $address->getId() == $this->_multishipping->getCustomer()->getDefaultShipping();
153  }
154 
161  public function getEditAddressUrl(\Magento\Customer\Api\Data\AddressInterface $address)
162  {
163  return $this->getUrl('*/*/editAddress', ['id' => $address->getId()]);
164  }
165 
172  public function getSetAddressUrl(\Magento\Customer\Api\Data\AddressInterface $address)
173  {
174  return $this->getUrl('*/*/setBilling', ['id' => $address->getId()]);
175  }
176 
180  public function getAddNewUrl()
181  {
182  return $this->getUrl('*/*/newBilling');
183  }
184 
188  public function getBackUrl()
189  {
190  return $this->getUrl('*/checkout/billing');
191  }
192 }
isAddressDefaultShipping(\Magento\Customer\Api\Data\AddressInterface $address)
Definition: Select.php:150
getData($key='', $index=null)
Definition: DataObject.php:119
getAddressAsHtml(\Magento\Customer\Api\Data\AddressInterface $address)
Definition: Select.php:123
$addresses
Definition: address_list.php:7
isAddressDefaultBilling(\Magento\Customer\Api\Data\AddressInterface $address)
Definition: Select.php:139
__()
Definition: __.php:13
$address
Definition: customer.php:38
getEditAddressUrl(\Magento\Customer\Api\Data\AddressInterface $address)
Definition: Select.php:161
getSetAddressUrl(\Magento\Customer\Api\Data\AddressInterface $address)
Definition: Select.php:172
setData($key, $value=null)
Definition: DataObject.php:72
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping, CustomerAddressHelper $customerAddressHelper, \Magento\Customer\Model\Address\Mapper $addressMapper, AddressRepositoryInterface $addressRepository, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Framework\Api\FilterBuilder $filterBuilder, array $data=[])
Definition: Select.php:63