I'm trying to create a "SmartSearch" extension for Magento 2.0, but I really can't find out what the next step should be. What I have so far:
- Working 2.0 Extension (registration.php, module is enabled and recognized)
- I override the default autocomplete function by using this code:
With this code I can manipulate the default autocomplete text. This is my SearchDataProvider:
class SearchDataProvider extends \Magento\CatalogSearch\Model\Autocomplete\DataProvider {
/**
* {@inheritdoc}
*/
public function getItems()
{
$collection = $this->getSuggestCollection();
$query = $this->queryFactory->get()->getQueryText();
$result = [];
foreach ($collection as $item) {
$resultItem = $this->itemFactory->create([
'title' => $item->getQueryText(),
'data' => $item->getData(),
'num_results' => $item->getNumResults(),
]);
if ($resultItem->getTitle() == $query) {
array_unshift($result, $resultItem);
} else {
$result[] = $resultItem;
}
}
return $result;
}
/**
* Retrieve suggest collection for query
*
* @return Collection
*/
private function getSuggestCollection()
{
return $this->queryFactory->get()->getSuggestCollection();
}
}
If i add something after 'title', it's shown in the autocomplete dropdown.
What I want to do now is to load another provider that will return a collection of products that contain the search query text.
I already found a FullText search model, but I cannot figure out how to properly use this.
Does anyone have experience with creating a search collection in Magento 2.0?