-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathReindexPostAfterSave.php
More file actions
executable file
·47 lines (40 loc) · 1.18 KB
/
ReindexPostAfterSave.php
File metadata and controls
executable file
·47 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Comwrap\ElasticsuiteBlog\Plugin\Indexer\Post\Save;
use Magento\Framework\Indexer\IndexerRegistry;
use Comwrap\ElasticsuiteBlog\Model\Post\Indexer\Fulltext;
use Magefan\Blog\Model\Post;
#[\AllowDynamicProperties]
class ReindexPostAfterSave
{
/**
* @var \Magento\Framework\Indexer\IndexerRegistry
*/
private $indexerRegistry;
/**
* ReindexCategoryAfterSave constructor.
*
* @param IndexerRegistry $indexerRegistry The indexer registry
*/
public function __construct(IndexerRegistry $indexerRegistry)
{
$this->indexerRegistry = $indexerRegistry;
}
/**
* Reindex blog posts data into search engine after saving the blog post
*
* @param Post $subject The blog post being reindexed
* @param Post $result The parent function we are plugged on
*
* @return \Magefan\Blog\Model\Post
*/
public function afterSave(
Post $subject,
$result
) {
if ($subject->getIsSearchable()) {
$blogPostIndexer = $this->indexerRegistry->get(Fulltext::INDEXER_ID);
$blogPostIndexer->reindexRow($subject->getId());
}
return $result;
}
}