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