collectionFactory->create(); $table = $collection->getMainTable(); $rows = $collection->getConnection()->fetchAll( 'select MIN(collection_name) AS collection_name, collection_sort from '.$table .' group by collection_sort order by collection_sort asc' ); $data = []; foreach ($rows as $row) { $data[] = ['collection_name'=>$row['collection_name']]; } return array_values($data); } /** * @return string */ public function execute() { $collectionName = trim((string)$this->restRequest->getParam('collection')); $page = intval($this->restRequest->getParam('page', 1)); $collection = $this->collectionFactory->create(); if (!empty($collectionName)) { $collection->addFieldToFilter('collection_name', $collectionName); } $collection->setPageSize(self::PAGE_SIZE)->setCurPage($page)->setOrder('collection_sort', 'asc'); $mediaUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); $data = $collection->getData(); foreach ($data as &$item) { $item['image'] = $mediaUrl . $item['image']; } return json_encode([ 'data'=>['items' => $data, 'total_count'=>$collection->getSize()], 'filters' => ['collection'=>$this->getFilters()] ]); } }