6
6
7
7
namespace Magento \Customer \Model ;
8
8
9
+ use Magento \Framework \Indexer \StateInterface ;
10
+
9
11
/**
10
12
* Class Visitor
11
13
* @package Magento\Customer\Model
@@ -55,15 +57,21 @@ class Visitor extends \Magento\Framework\Model\AbstractModel
55
57
*/
56
58
protected $ dateTime ;
57
59
60
+ /**
61
+ * @var \Magento\Framework\Indexer\IndexerRegistry
62
+ */
63
+ protected $ indexerRegistry ;
64
+
58
65
/**
59
66
* @param \Magento\Framework\Model\Context $context
60
67
* @param \Magento\Framework\Registry $registry
61
68
* @param \Magento\Framework\Session\SessionManagerInterface $session
62
69
* @param \Magento\Framework\HTTP\Header $httpHeader
63
- * @param \Magento\Framework\Model\Resource\AbstractResource $resource
64
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
65
70
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
66
71
* @param \Magento\Framework\Stdlib\DateTime $dateTime
72
+ * @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
73
+ * @param \Magento\Framework\Model\Resource\AbstractResource|null $resource
74
+ * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
67
75
* @param array $ignoredUserAgents
68
76
* @param array $ignores
69
77
* @param array $data
@@ -77,6 +85,7 @@ public function __construct(
77
85
\Magento \Framework \HTTP \Header $ httpHeader ,
78
86
\Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
79
87
\Magento \Framework \Stdlib \DateTime $ dateTime ,
88
+ \Magento \Framework \Indexer \IndexerRegistry $ indexerRegistry ,
80
89
\Magento \Framework \Model \Resource \AbstractResource $ resource = null ,
81
90
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
82
91
array $ ignoredUserAgents = [],
@@ -90,6 +99,7 @@ public function __construct(
90
99
$ this ->ignores = $ ignores ;
91
100
$ this ->scopeConfig = $ scopeConfig ;
92
101
$ this ->dateTime = $ dateTime ;
102
+ $ this ->indexerRegistry = $ indexerRegistry ;
93
103
}
94
104
95
105
/**
@@ -149,6 +159,34 @@ public function initByRequest($observer)
149
159
return $ this ;
150
160
}
151
161
162
+ /**
163
+ * Processing object after save data
164
+ *
165
+ * @return $this
166
+ */
167
+ public function afterSave ()
168
+ {
169
+ $ indexer = $ this ->indexerRegistry ->get (Customer::CUSTOMER_GRID_INDEXER_ID );
170
+ if ($ indexer ->getState ()->getStatus () !== StateInterface::STATUS_INVALID ) {
171
+ $ this ->_getResource ()->addCommitCallback ([$ this , 'reindex ' ]);
172
+ }
173
+ return parent ::afterSave ();
174
+ }
175
+
176
+ /**
177
+ * Init indexing process after visitor save
178
+ *
179
+ * @return void
180
+ */
181
+ public function reindex ()
182
+ {
183
+ if ($ this ->getCustomerId ()) {
184
+ /** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
185
+ $ indexer = $ this ->indexerRegistry ->get (Customer::CUSTOMER_GRID_INDEXER_ID );
186
+ $ indexer ->reindexRow ($ this ->getCustomerId ());
187
+ }
188
+ }
189
+
152
190
/**
153
191
* Save visitor by request
154
192
*
0 commit comments