diff --git a/Model/Autocomplete/Page/DataProvider.php b/Model/Autocomplete/Page/DataProvider.php index 0c296c2..0635960 100644 --- a/Model/Autocomplete/Page/DataProvider.php +++ b/Model/Autocomplete/Page/DataProvider.php @@ -20,6 +20,7 @@ use Smile\ElasticsuiteCore\Helper\Autocomplete as ConfigurationHelper; use Smile\ElasticsuiteCms\Model\ResourceModel\Page\Fulltext\CollectionFactory as CmsCollectionFactory; use Smile\ElasticsuiteCore\Model\Autocomplete\Terms\DataProvider as TermDataProvider; +use Magento\Framework\Event\ManagerInterface as EventManager; /** * Catalog product autocomplete data provider. @@ -71,6 +72,11 @@ class DataProvider implements DataProviderInterface */ protected $storeManager; + /** + * @var EventManager + */ + protected $eventManager; + /** * @var string Autocomplete result type */ @@ -85,6 +91,7 @@ class DataProvider implements DataProviderInterface * @param CmsCollectionFactory $cmsCollectionFactory Cms collection factory. * @param ConfigurationHelper $configurationHelper Autocomplete configuration helper. * @param StoreManagerInterface $storeManager Store manager. + * @param EventManager $eventManager Event dispatcher * @param string $type Autocomplete provider type. */ public function __construct( @@ -94,6 +101,7 @@ public function __construct( CmsCollectionFactory $cmsCollectionFactory, ConfigurationHelper $configurationHelper, StoreManagerInterface $storeManager, + EventManager $eventManager, $type = self::AUTOCOMPLETE_TYPE ) { $this->itemFactory = $itemFactory; @@ -101,6 +109,7 @@ public function __construct( $this->termDataProvider = $termDataProvider; $this->cmsCollectionFactory = $cmsCollectionFactory; $this->configurationHelper = $configurationHelper; + $this->eventManager = $eventManager; $this->type = $type; $this->storeManager = $storeManager; } @@ -122,15 +131,22 @@ public function getItems() $pageCollection = $this->getCmsPageCollection(); if ($pageCollection) { foreach ($pageCollection as $page) { - $result[] = $this->itemFactory->create( + $item = $this->itemFactory->create( [ 'title' => $page->getTitle(), 'url' => $this->storeManager->getStore()->getBaseUrl(). $page->getIdentifier(), 'type' => $this->getType(), ] ); + + $this->eventManager->dispatch( + 'smile_elasticsuite_cms_search_autocomplete_page_item', + ['page' => $page, 'item' => $item] + ); + + $result[] = $item; } - } + } } return $result;