Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EVOL] Add event dispatch for customize autocomplete item #32

Merged
merged 2 commits into from
Aug 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Model/Autocomplete/Page/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -71,6 +72,11 @@ class DataProvider implements DataProviderInterface
*/
protected $storeManager;

/**
* @var EventManager
*/
protected $eventManager;

/**
* @var string Autocomplete result type
*/
Expand All @@ -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(
Expand All @@ -94,13 +101,15 @@ public function __construct(
CmsCollectionFactory $cmsCollectionFactory,
ConfigurationHelper $configurationHelper,
StoreManagerInterface $storeManager,
EventManager $eventManager,
$type = self::AUTOCOMPLETE_TYPE
) {
$this->itemFactory = $itemFactory;
$this->queryFactory = $queryFactory;
$this->termDataProvider = $termDataProvider;
$this->cmsCollectionFactory = $cmsCollectionFactory;
$this->configurationHelper = $configurationHelper;
$this->eventManager = $eventManager;
$this->type = $type;
$this->storeManager = $storeManager;
}
Expand All @@ -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;
Expand Down