resource = $resource; $this->tissueFactory = $tissueFactory; $this->tissueCollectionFactory = $tissueCollectionFactory; $this->searchResultsFactory = $searchResultsFactory; $this->collectionProcessor = $collectionProcessor; } /** * @inheritDoc */ public function save(TissueInterface $tissue) { try { $this->resource->save($tissue); } catch (\Exception $exception) { throw new CouldNotSaveException(__( 'Could not save the tissue: %1', $exception->getMessage() )); } return $tissue; } /** * @inheritDoc */ public function get($tissueId) { $tissue = $this->tissueFactory->create(); $this->resource->load($tissue, $tissueId); if (!$tissue->getId()) { throw new NoSuchEntityException(__('Tissue with id "%1" does not exist.', $tissueId)); } return $tissue; } /** * @inheritDoc */ public function getList( \Magento\Framework\Api\SearchCriteriaInterface $criteria ) { $collection = $this->tissueCollectionFactory->create(); $this->collectionProcessor->process($criteria, $collection); $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($criteria); $items = []; foreach ($collection as $model) { $items[] = $model; } $searchResults->setItems($items); $searchResults->setTotalCount($collection->getSize()); return $searchResults; } /** * @inheritDoc */ public function delete(TissueInterface $tissue) { try { $tissueModel = $this->tissueFactory->create(); $this->resource->load($tissueModel, $tissue->getTissueId()); $this->resource->delete($tissueModel); } catch (\Exception $exception) { throw new CouldNotDeleteException(__( 'Could not delete the Tissue: %1', $exception->getMessage() )); } return true; } /** * @inheritDoc */ public function deleteById($tissueId) { return $this->delete($this->get($tissueId)); } }