resource = $resource; $this->cryopreserveFactory = $cryopreserveFactory; $this->cryopreserveCollectionFactory = $cryopreserveCollectionFactory; $this->searchResultsFactory = $searchResultsFactory; $this->collectionProcessor = $collectionProcessor; } /** * @inheritDoc */ public function save(CryopreserveInterface $cryopreserve) { try { $this->resource->save($cryopreserve); } catch (\Exception $exception) { throw new CouldNotSaveException(__( 'Could not save the cryopreserve: %1', $exception->getMessage() )); } return $cryopreserve; } /** * @inheritDoc */ public function get($cryopreserveId) { $cryopreserve = $this->cryopreserveFactory->create(); $this->resource->load($cryopreserve, $cryopreserveId); if (!$cryopreserve->getId()) { throw new NoSuchEntityException(__('cryopreserve with id "%1" does not exist.', $cryopreserveId)); } return $cryopreserve; } /** * @inheritDoc */ public function getList( \Magento\Framework\Api\SearchCriteriaInterface $criteria ) { $collection = $this->cryopreserveCollectionFactory->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(CryopreserveInterface $cryopreserve) { try { $cryopreserveModel = $this->cryopreserveFactory->create(); $this->resource->load($cryopreserveModel, $cryopreserve->getCryopreserveId()); $this->resource->delete($cryopreserveModel); } catch (\Exception $exception) { throw new CouldNotDeleteException(__( 'Could not delete the cryopreserve: %1', $exception->getMessage() )); } return true; } /** * @inheritDoc */ public function deleteById($cryopreserveId) { return $this->delete($this->get($cryopreserveId)); } }