/** * List of enabled indexes * * @return \Mirasvit\Search\Model\Index[] */ public function getIndexes() { if ($this->indexes == null) { $result = []; $collection = $this->indexCollectionFactory->create()->addFieldToFilter('is_active', 1)->setOrder('position', 'asc'); /** @var \Mirasvit\Search\Model\Index $index */ foreach ($collection as $index) { if ($this->config->isMultiStoreModeEnabled() && $index->getCode() == 'catalogsearch_fulltext') { foreach ($this->_storeManager->getStores(false, true) as $code => $store) { if (in_array($store->getId(), $this->config->getEnabledMultiStores())) { $clone = clone $index; $clone->setData('store_id', $store->getId()); $clone->setData('store_code', $code); if ($this->_storeManager->getStore()->getId() != $store->getId()) { $clone->setData('title', $store->getName()); } $result[] = $clone; } } } else { $result[] = $index; } } $this->indexes = $result; } return $this->indexes; }
/** * {@inheritdoc} */ protected function buildSearchCollection() { /** @var \Magento\Catalog\Model\Layer\Search $layer */ $layer = $this->layerResolver->get(); if ($this->config->isMultiStoreModeEnabled()) { $originalCategory = $layer->getData('current_category'); // set random category for multi-store mode // this mode can be not compatible with some layered navigation $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $category = $objectManager->create('Magento\\Catalog\\Model\\Category'); $category->setId(rand(100000, 900000)); $layer->setData('current_category', $category); } $collection = $layer->getProductCollection(); if ($this->config->isMultiStoreModeEnabled()) { $layer->setData('current_category', $originalCategory); } return $collection; }