resource = $resource; $this->carouselFactory = $carouselFactory; $this->carouselCollectionFactory = $carouselCollectionFactory; $this->searchResultsFactory = $searchResultsFactory; $this->dataObjectHelper = $dataObjectHelper; $this->dataCarouselFactory = $dataCarouselFactory; $this->dataObjectProcessor = $dataObjectProcessor; $this->storeManager = $storeManager; $this->collectionProcessor = $collectionProcessor; $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; $this->extensibleDataObjectConverter = $extensibleDataObjectConverter; } /** * {@inheritdoc} */ public function save( CarouselInterface $carousel ) { /* if (empty($carousel->getStoreId())) { $storeId = $this->storeManager->getStore()->getId(); $carousel->setStoreId($storeId); } */ $carouselData = $this->extensibleDataObjectConverter->toNestedArray( $carousel, [], CarouselInterface::class ); $carouselModel = $this->carouselFactory->create()->setData($carouselData); try { $this->resource->save($carouselModel); } catch (Exception $exception) { throw new CouldNotSaveException(__( 'Could not save the carousel: %1', $exception->getMessage() )); } return $carouselModel->getDataModel(); } /** * {@inheritdoc} */ public function getList( SearchCriteriaInterface $criteria ) { $collection = $this->carouselCollectionFactory->create(); $this->extensionAttributesJoinProcessor->process( $collection, CarouselInterface::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($carouselId) { return $this->delete($this->get($carouselId)); } /** * {@inheritdoc} */ public function delete( CarouselInterface $carousel ) { try { $carouselModel = $this->carouselFactory->create(); $this->resource->load($carouselModel, $carousel->getCarouselId()); $this->resource->delete($carouselModel); } catch (Exception $exception) { throw new CouldNotDeleteException(__( 'Could not delete the Carousel: %1', $exception->getMessage() )); } return true; } /** * {@inheritdoc} */ public function get($carouselId) { $carousel = $this->carouselFactory->create(); $this->resource->load($carousel, $carouselId); if (!$carousel->getId()) { throw new NoSuchEntityException(__('Carousel with id "%1" does not exist.', $carouselId)); } return $carousel->getDataModel(); } }