_filterGridFactory = $filterGridFactory; $this->_multishipping = $multishipping; $this->customerRepository = $customerRepository; $this->_addressConfig = $addressConfig; parent::__construct($context, $data); $this->addressMapper = $addressMapper; $this->_isScopePrivate = true; } /** * Retrieve multishipping checkout model * * @return \Magento\Multishipping\Model\Checkout\Type\Multishipping */ public function getCheckout() { return $this->_multishipping; } /** * @return $this */ protected function _prepareLayout() { $this->pageConfig->getTitle()->set( __('Ship to Multiple Addresses') . ' - ' . $this->pageConfig->getTitle()->getDefault() ); return parent::_prepareLayout(); } /** * @return array */ public function getItems() { $items = $this->getCheckout()->getQuoteShippingAddressesItems(); /** @var \Magento\Framework\Filter\DataObject\Grid $itemsFilter */ $itemsFilter = $this->_filterGridFactory->create(); $itemsFilter->addFilter(new \Magento\Framework\Filter\Sprintf('%d'), 'qty'); return $itemsFilter->filter($items); } /** * Retrieve HTML for addresses dropdown * * @param mixed $item * @param int $index * @return string */ public function getAddressesHtmlSelect($item, $index) { $select = $this->getLayout()->createBlock(\Magento\Framework\View\Element\Html\Select::class) ->setName('ship[' . $index . '][' . $item->getQuoteItemId() . '][address]') ->setId('ship_' . $index . '_' . $item->getQuoteItemId() . '_address') ->setValue($item->getCustomerAddressId()) ->setOptions($this->getAddressOptions()); return $select->getHtml(); } /** * Retrieve options for addresses dropdown * * @return array */ public function getAddressOptions() { $options = $this->getData('address_options'); if ($options === null) { $options = []; $addresses = []; try { $addresses = $this->customerRepository->getById($this->getCustomerId())->getAddresses(); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { /** Customer does not exist */ } /** @var \Magento\Customer\Api\Data\AddressInterface $address */ foreach ($addresses as $address) { $label = $this->_addressConfig ->getFormatByCode(AddressConfig::DEFAULT_ADDRESS_FORMAT) ->getRenderer() ->renderArray($this->addressMapper->toFlatArray($address)); $options[] = [ 'value' => $address->getId(), 'label' => $label, ]; } $this->setData('address_options', $options); } return $options; } /** * Retrieve active customer ID * * @return int|null */ public function getCustomerId() { return $this->getCheckout()->getCustomerSession()->getCustomerId(); } /** * @param mixed $item * @return string */ public function getItemUrl($item) { return $this->getUrl('catalog/product/view/id/' . $item->getProductId()); } /** * @param mixed $item * @return string */ public function getItemDeleteUrl($item) { return $this->getUrl('*/*/removeItem', ['address' => $item->getQuoteAddressId(), 'id' => $item->getId()]); } /** * @return string */ public function getPostActionUrl() { return $this->getUrl('*/*/addressesPost'); } /** * @return string */ public function getNewAddressUrl() { return $this->getUrl('*/checkout_address/newShipping'); } /** * @return string */ public function getBackUrl() { return $this->getUrl('checkout/cart/'); } /** * @return bool */ public function isContinueDisabled() { return !$this->getCheckout()->validateMinimumAmount(); } }