コード例 #1
0
ファイル: Result.php プロジェクト: Doability/magento2dev
 /**
  * Convert all results to array
  *
  * @return array
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function toArray()
 {
     $result = ['totalItems' => 0, 'query' => $this->query->getQueryText(), 'indexes' => [], 'noResults' => false, 'urlAll' => $this->searchHelper->getResultUrl($this->query->getQueryText())];
     /** @var \Mirasvit\Search\Model\Index $index */
     foreach ($this->getIndexes() as $index) {
         $indexCode = $index->getCode();
         if ($indexCode == 'catalogsearch_fulltext') {
             $indexCode = 'magento_catalog_product';
         }
         $collection = $this->getCollection($index);
         $localIndex = $this->indexPool->get($indexCode);
         $localIndex->setCollection($collection);
         $items = ['code' => $indexCode, 'title' => $index->getTitle(), 'totalItems' => $collection->getSize(), 'isShowTotals' => $indexCode == 'magento_search_query' ? false : true, 'items' => $localIndex->getItems()];
         $result['indexes'][] = $items;
         $result['totalItems'] += $localIndex->getSize();
     }
     $result['textAll'] = __('Show all %1 results →', $result['totalItems']);
     $result['textEmpty'] = __('Sorry, nothing found for "%1".', $result['query']);
     $result['noResults'] = $result['totalItems'] ? false : true;
     return $result;
 }