resource = $resource; $this->locationFactory = $locationFactory; $this->locationCollectionFactory = $locationCollectionFactory; $this->searchResultsFactory = $searchResultsFactory; $this->dataObjectHelper = $dataObjectHelper; $this->dataLocationFactory = $dataLocationFactory; $this->dataObjectProcessor = $dataObjectProcessor; $this->storeManager = $storeManager; $this->collectionProcessor = $collectionProcessor; $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; $this->extensibleDataObjectConverter = $extensibleDataObjectConverter; } /** * {@inheritdoc} */ public function save( LocationInterface $location ) { /* if (empty($location->getStoreId())) { $storeId = $this->storeManager->getStore()->getId(); $location->setStoreId($storeId); } */ $locationData = $this->extensibleDataObjectConverter->toNestedArray( $location, [], LocationInterface::class ); $locationModel = $this->locationFactory->create()->setData($locationData); try { $this->resource->save($locationModel); } catch (Exception $exception) { throw new CouldNotSaveException(__( 'Could not save the location: %1', $exception->getMessage() )); } return $locationModel->getDataModel(); } /** * {@inheritdoc} */ public function getList( SearchCriteriaInterface $criteria ) { $collection = $this->locationCollectionFactory->create(); $this->extensionAttributesJoinProcessor->process( $collection, LocationInterface::class ); $this->collectionProcessor->process($criteria, $collection); $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($criteria); $items = []; foreach ($collection as $model) { $items[] = $model->getDataModel(); } $searchResults->setItems($items); $searchResults->setTotalCount($collection->getSize()); return $searchResults; } /** * {@inheritdoc} */ public function deleteById($locationId) { return $this->delete($this->get($locationId)); } /** * {@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 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->getDataModel(); } }