コード例 #1
0
 /**
  * Retrieve teaserItems matching the specified criteria.
  *
  * @param SearchCriteriaInterface $searchCriteria
  *
  * @return Data\TeaserItemSearchResultInterface
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     /** @var Data\TeaserItemSearchResultInterface $searchResults */
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     /** @var TeaserItemResource\Collection $collection */
     $collection = $this->teaserItemCollectionFactory->create();
     foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
         foreach ($filterGroup->getFilters() as $filter) {
             $condition = $filter->getConditionType() ?: 'eq';
             $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
         }
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $teaserItems = [];
     /** @var TeaserItem $teaserItemModel */
     foreach ($collection as $teaserItemModel) {
         $teaserItemData = $this->teaserItemFactory->create();
         $this->dataObjectHelper->populateWithArray($teaserItemData, $teaserItemModel->getData(), Data\TeaserItemInterface::class);
         $teaserItems[] = $this->dataObjectProcessor->buildOutputDataArray($teaserItemData, Data\TeaserItemInterface::class);
     }
     $searchResults->setItems($teaserItems);
     return $searchResults;
 }
コード例 #2
0
 /**
  * DataProvider constructor.
  *
  * @param string                      $name
  * @param string                      $primaryFieldName
  * @param string                      $requestFieldName
  * @param TeaserItemCollectionFactory $teaserItemCollectionFactory
  * @param array                       $meta
  * @param array                       $data
  */
 public function __construct($name, $primaryFieldName, $requestFieldName, TeaserItemCollectionFactory $teaserItemCollectionFactory, array $meta = [], array $data = [])
 {
     parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
     $this->collection = $teaserItemCollectionFactory->create();
 }