9
9
use Magento \Framework \Module \Manager as ModuleManager ;
10
10
use Magento \Framework \ObjectManagerInterface ;
11
11
use Magento \Framework \UrlInterface ;
12
+ use Magento \Framework \View \Asset \Repository as AssetRepository ;
12
13
13
14
class NoticeHelper extends \Magento \Framework \App \Helper \AbstractHelper
14
15
{
@@ -35,6 +36,9 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper
35
36
/** @var UrlInterface */
36
37
protected $ urlBuilder ;
37
38
39
+ /** @var AssetRepository */
40
+ protected $ assetRepository ;
41
+
38
42
/** @var string[] */
39
43
protected $ noticeFunctions = [
40
44
'getQueueNotice ' ,
@@ -43,6 +47,16 @@ class NoticeHelper extends \Magento\Framework\App\Helper\AbstractHelper
43
47
'getVersionNotice ' ,
44
48
'getClickAnalyticsNotice ' ,
45
49
'getQueryRulesNotice ' ,
50
+ 'getPersonalizationNotice ' ,
51
+ ];
52
+
53
+ /** @var array[] */
54
+ protected $ pagesWithoutQueueNotice = [
55
+ 'algoliasearch_cc_analytics ' ,
56
+ 'algoliasearch_analytics ' ,
57
+ 'algoliasearch_personalization ' ,
58
+ 'algoliasearch_advanced ' ,
59
+ 'algoliasearch_extra_settings ' ,
46
60
];
47
61
48
62
/** @var array[] */
@@ -56,7 +70,8 @@ public function __construct(
56
70
ObjectManagerInterface $ objectManager ,
57
71
ExtensionNotification $ extensionNotification ,
58
72
JobCollectionFactory $ jobCollectionFactory ,
59
- UrlInterface $ urlBuilder
73
+ UrlInterface $ urlBuilder ,
74
+ AssetRepository $ assetRepository
60
75
) {
61
76
$ this ->configHelper = $ configHelper ;
62
77
$ this ->proxyHelper = $ proxyHelper ;
@@ -65,6 +80,7 @@ public function __construct(
65
80
$ this ->extensionNotification = $ extensionNotification ;
66
81
$ this ->jobCollectionFactory = $ jobCollectionFactory ;
67
82
$ this ->urlBuilder = $ urlBuilder ;
83
+ $ this ->assetRepository = $ assetRepository ;
68
84
69
85
foreach ($ this ->noticeFunctions as $ noticeFunction ) {
70
86
call_user_func ([$ this , $ noticeFunction ]);
@@ -79,6 +95,12 @@ public function getExtensionNotices()
79
95
80
96
protected function getQueueNotice ()
81
97
{
98
+ foreach ($ this ->pagesWithoutQueueNotice as $ page ) {
99
+ if (preg_match ('/ ' . $ page . '/ ' , $ this ->urlBuilder ->getCurrentUrl ())) {
100
+ return ;
101
+ }
102
+ }
103
+
82
104
$ jobCollection = $ this ->jobCollectionFactory ->create ();
83
105
$ size = $ jobCollection ->getSize ();
84
106
$ maxJobsPerSingleRun = $ this ->configHelper ->getNumberOfJobToRun ();
@@ -237,6 +259,65 @@ protected function getQueryRulesNotice()
237
259
];
238
260
}
239
261
262
+ protected function getPersonalizationNotice ()
263
+ {
264
+ if (! preg_match ('/algoliasearch_personalization/ ' , $ this ->urlBuilder ->getCurrentUrl ())) {
265
+ return ;
266
+ }
267
+
268
+ $ personalizationStatus = $ this ->getPersonalizationStatus ();
269
+
270
+ // Adding header
271
+ $ docContent = '<h2 class="algolia-perso-title">Personalization</h2> ' ;
272
+
273
+ if ($ personalizationStatus < 2 ) {
274
+ $ docContent .= '<div class="perso-illustration">
275
+ <img src=" ' . $ this ->assetRepository ->getUrl ('Algolia_AlgoliaSearch::images/illu-perso.svg ' ) . '"/>
276
+ </div> ' ;
277
+ }
278
+
279
+ $ docContent .= '<div class="algolia_block icon-documentation algoblue">
280
+ <div class="heading"></div>
281
+ Personalization brings another level of relevant search results to your customers.<br/>
282
+ Find out more in our <a href="https://www.algolia.com/doc/guides/getting-insights-and-analytics/personalization/what-is-personalization/" target="_blank`">Documentation</a>.
283
+ </div> ' ;
284
+
285
+ switch ($ personalizationStatus ) {
286
+ // Activated
287
+ case 2 : $ warningContent = 'Personalization is based on actions a user has performed in the past. We help you collect some of the data automatically.</br>
288
+ After you \'ve collected a reasonable amount of data, Personlization can be applied. ' ;
289
+ $ icon = 'icon-warning ' ;
290
+ break ;
291
+ // Available but not activated
292
+ case 1 : $ warningContent = 'To start using this feature, please head over the <a href="https://www.algolia.com/dashboard" target="_blank`">Algolia Dashboard</a>,
293
+ and make sure you \'ve enabled Personalization in your account, as well as agreed to the terms and conditions of using Personalization. ' ;
294
+ $ icon = 'icon-warning ' ;
295
+ break ;
296
+ // Not Available
297
+ default : $ warningContent = 'To get access to this Algolia feature, please <a target="_blank" href="https://www.algolia.com/contact/enterprise/">contact us</a>. ' ;
298
+ $ icon = 'icon-stars ' ;
299
+ break ;
300
+ }
301
+
302
+ $ docContent .= $ this ->formatNotice ('' , $ warningContent , $ icon );
303
+
304
+ $ this ->notices [] = [
305
+ 'selector ' => '.entry-edit ' ,
306
+ 'method ' => 'before ' ,
307
+ 'message ' => $ docContent ,
308
+ ];
309
+
310
+ // Adding footer
311
+ $ footerContent = '<div class="algolia-perso-footer"><br/><h2>Personlization preferences</h2>
312
+ <p>Manage your Personalization further on the <a href="https://www.algolia.com/dashboard" target="_blank`">Algolia Dashboard</a></p></div> ' ;
313
+
314
+ $ this ->notices [] = [
315
+ 'selector ' => '#algoliasearch_personalization_personalization_group_personalization_conversion_events_group ' ,
316
+ 'method ' => 'after ' ,
317
+ 'message ' => $ footerContent ,
318
+ ];
319
+ }
320
+
240
321
protected function formatNotice ($ title , $ content , $ icon = 'icon-warning ' )
241
322
{
242
323
return '<div class="algolia_block ' . $ icon . '">
@@ -245,6 +326,33 @@ protected function formatNotice($title, $content, $icon = 'icon-warning')
245
326
</div> ' ;
246
327
}
247
328
329
+ /**
330
+ * 0 for non available
331
+ * 1 for available but not activated
332
+ * 2 for activated
333
+ *
334
+ * @return int
335
+ */
336
+ public function getPersonalizationStatus ()
337
+ {
338
+ $ info = $ this ->proxyHelper ->getInfo (ProxyHelper::INFO_TYPE_PERSONALIZATION );
339
+
340
+ $ status = 2 ;
341
+
342
+ if ($ info
343
+ && array_key_exists ('personalization ' , $ info )
344
+ && array_key_exists ('personalization_enabled_at ' , $ info )) {
345
+ if (!$ info ['personalization ' ]) {
346
+ $ status = 0 ;
347
+ }
348
+ if ($ info ['personalization_enabled_at ' ] === null ) {
349
+ $ status = min (1 , $ status );
350
+ }
351
+ }
352
+
353
+ return $ status ;
354
+ }
355
+
248
356
/** @return bool */
249
357
public function isQueryRulesEnabled ()
250
358
{
0 commit comments