addressCollectionFactory = $addressCollectionFactory; } /** * @throws NoSuchEntityException * @throws \Magento\Framework\Exception\LocalizedException */ protected function _prepareLayout(): Book { parent::_prepareLayout(); $pager = $this->getChildBlock('pager'); if ($pager===false) { $pager = $this->getLayout()->createBlock(Pager::class, 'customer.addresses.pager'); $this->setChild('pager', $pager); } $pager->setCollection($this->getAddressCollection()); return $this; } /** * Get customer addresses collection. * * Filters collection by customer id * * @return Collection * @throws NoSuchEntityException */ public function getAddressCollection(): Collection { if (null === $this->addressCollection) { if (null === $this->getCustomer()) { throw new NoSuchEntityException(__('Customer not logged in')); } $collection = $this->addressCollectionFactory->create(); $collection->setOrder('entity_id', 'desc'); $collection->setCustomerFilter([$this->getCustomer()->getId()]); $this->addressCollection = $collection; } return $this->addressCollection; } }