metadata = $invoiceMetadata; $this->searchResultFactory = $searchResultFactory; $this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor(); } /** * Load entity * * @param int $id * @return mixed * @throws NoSuchEntityException * @throws \Magento\Framework\Exception\InputException */ public function get($id) { if (!$id) { throw new \Magento\Framework\Exception\InputException(__('An ID is needed. Set the ID and try again.')); } if (!isset($this->registry[$id])) { /** @var \Magento\Sales\Api\Data\InvoiceInterface $entity */ $entity = $this->metadata->getNewInstance()->load($id); if (!$entity->getEntityId()) { throw new NoSuchEntityException( __("The entity that was requested doesn't exist. Verify the entity and try again.") ); } $this->registry[$id] = $entity; } return $this->registry[$id]; } /** * @return \Magento\Sales\Api\Data\InvoiceInterface */ public function create() { return $this->metadata->getNewInstance(); } /** * Find entities by criteria * * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return \Magento\Sales\Api\Data\InvoiceInterface[] */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { /** @var \Magento\Sales\Model\ResourceModel\Order\Invoice\Collection $collection */ $collection = $this->searchResultFactory->create(); $this->collectionProcessor->process($searchCriteria, $collection); $collection->setSearchCriteria($searchCriteria); return $collection; } /** * Register entity to delete * * @param \Magento\Sales\Api\Data\InvoiceInterface $entity * @return bool */ public function delete(\Magento\Sales\Api\Data\InvoiceInterface $entity) { $this->metadata->getMapper()->delete($entity); unset($this->registry[$entity->getEntityId()]); return true; } /** * Delete entity by Id * * @param int $id * @return bool */ public function deleteById($id) { $entity = $this->get($id); return $this->delete($entity); } /** * Perform persist operations for one entity * * @param \Magento\Sales\Api\Data\InvoiceInterface $entity * @return \Magento\Sales\Api\Data\InvoiceInterface */ public function save(\Magento\Sales\Api\Data\InvoiceInterface $entity) { $this->metadata->getMapper()->save($entity); $this->registry[$entity->getEntityId()] = $entity; return $this->registry[$entity->getEntityId()]; } /** * Retrieve collection processor * * @deprecated 101.0.0 * @return CollectionProcessorInterface */ private function getCollectionProcessor() { if (!$this->collectionProcessor) { $this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get( \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class ); } return $this->collectionProcessor; } }