-
Notifications
You must be signed in to change notification settings - Fork 5
/
nostotagging.php
1268 lines (1169 loc) · 43.1 KB
/
nostotagging.php
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php /** @noinspection PhpFullyQualifiedNameUsageInspection */
/**
* 2013-2022 Nosto Solutions Ltd
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author Nosto Solutions Ltd <[email protected]>
* @copyright 2013-2022 Nosto Solutions Ltd
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
/*
* Only try to load class files if we can resolve the __FILE__ global to the current file.
* We need to do this as this module file is parsed with eval() on the modules page, and eval()
* messes up the __FILE__.
*/
if ((basename(__FILE__) === 'nostotagging.php')) {
define('NOSTO_DIR', dirname(__FILE__));
require_once(dirname(__FILE__) . "/bootstrap.php");
}
/**
* Main module class the is responsible for all the module behaviour. This class is to be kept
* lightweight with no more than single line method bodies that simply delegate to other services,
* helpers or manager.
*
* @property Context $context
* @property string $bootstrap
*/
class NostoTagging extends Module
{
const AJAX_REQUEST_PARAMETER_KEY = 'ajax';
/** @var bool */
public $bootstrap;
/**
* The version of the Nosto plug-in
*
* @var string
*/
const PLUGIN_VERSION = '4.4.1';
/**
* Internal name of the Nosto plug-in
*
* @var string
*/
const MODULE_NAME = 'nostotagging';
/**
* @var string the algorithm to use for hashing visitor id.
*/
const VISITOR_HASH_ALGO = 'sha256';
const ID = 'id';
private $topHookExecuted = false;
/**
* Custom hooks to add for this module.
*
* @var array
*/
protected static $customHooks = array(
array(
'name' => 'displayCategoryTop',
'title' => 'Category top',
'description' => 'Add new blocks above the category product list',
),
array(
'name' => 'displayCategoryFooter',
'title' => 'Category footer',
'description' => 'Add new blocks below the category product list',
),
array(
'name' => 'displaySearchTop',
'title' => 'Search top',
'description' => 'Add new blocks above the search result list.',
),
array(
'name' => 'displaySearchFooter',
'title' => 'Search footer',
'description' => 'Add new blocks below the search result list.',
),
array(
'name' => 'actionNostoCartLoadAfter',
'title' => 'After load nosto cart',
'description' => 'Action hook fired after a Nosto cart object has been loaded.',
),
array(
'name' => 'actionNostoOrderLoadAfter',
'title' => 'After load nosto order',
'description' => 'Action hook fired after a Nosto order object has been loaded.',
),
array(
'name' => 'actionNostoProductLoadAfter',
'title' => 'After load nosto product',
'description' => 'Action hook fired after a Nosto product object has been loaded.',
),
array(
'name' => 'actionNostoPriceVariantLoadAfter',
'title' => 'After load nosto price variation',
'description' => 'Action hook fired after a Nosto price variation object has been initialized.',
),
array(
'name' => 'actionNostoRatesLoadAfter',
'title' => 'After load nosto exchange rates',
'description' => 'Action hook fired after a Nosto exchange rate collection has been initialized.',
),
array(
'name' => 'actionNostoVariationKeyCollectionLoadAfter',
'title' => 'After load nosto variation key collection',
'description' => 'Action hook fired after a Nosto variation key collection has been initialized.',
),
array(
'name' => 'actionNostoCustomerLoadAfter',
'title' => 'After load nosto customer',
'description' => 'Action hook fired after a Nosto customer has been loaded.',
),
);
/**
* Constructor.
*
* Defines module attributes.
*
* @suppress PhanTypeMismatchProperty
*/
public function __construct()
{
$this->name = self::MODULE_NAME;
$this->tab = 'advertising_marketing';
$this->version = self::PLUGIN_VERSION;
$this->bootstrap = true; // Necessary for Bootstrap CSS initialisation in the UI
$this->author = 'Nosto';
$this->need_instance = 1;
$this->ps_versions_compliancy = array('min' => '1.5.5.0', 'max' => '8.2.0');
$this->module_key = '8d80397cab6ca02dfe8ef681b48c37a3';
parent::__construct();
$this->displayName = $this->l('Nosto Personalization for PrestaShop');
$this->description = $this->l(
'Increase your conversion rate and average order value by delivering your customers personalized product
recommendations throughout their shopping journey.'
);
\Nosto\Request\Http\HttpRequest::buildUserAgent(
'Prestashop',
_PS_VERSION_,
self::PLUGIN_VERSION
);
}
/**
* Installs the module.
*
* Initializes config, adds custom hooks and registers used hooks.
*
* @return bool
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @noinspection PhpUnused
*/
public function install()
{
$success = false;
if (parent::install()) {
$success = true;
if (!$this->registerHook('header')
|| !$this->registerHook('top')
|| !$this->registerHook('footer')
|| !$this->registerHook('productFooter')
|| !$this->registerHook('shoppingCart')
|| !$this->registerHook('postUpdateOrderStatus')
|| !$this->registerHook('paymentTop')
|| !$this->registerHook('home')
|| !$this->registerHook('actionCartSave')
|| !$this->registerHook('actionCartUpdateQuantityBefore')
|| !$this->registerHook('actionBeforeCartUpdateQty')
|| !$this->registerHook('actionCustomerAccountAdd')
|| !$this->registerHook('actionCustomerAccountUpdate')
) {
$success = false;
$this->_errors[] = $this->l(
'Failed to register hooks'
);
}
if (!NostoCustomerManager::createTables()) {
$success = false;
$this->_errors[] = $this->l('Failed to create Nosto customer table');
}
if (!NostoAdminTabManager::install()) {
$success = false;
$this->_errors[] = $this->l('Failed to create Nosto admin tab');
}
if (!NostoHookManager::initHooks(self::$customHooks)) {
$success = false;
$this->_errors[] = $this->l('Failed to register custom Nosto hooks');
}
// For versions < 1.5.3.1 we need to keep track of the currently installed version.
// This is to enable auto-update of the module by running its upgrade scripts.
// This config value is updated in the NostoTaggingUpdater helper every time the module is updated.
if ($success) {
$success = $this->registerHook('actionObjectUpdateAfter')
&& $this->registerHook('actionObjectDeleteAfter')
&& $this->registerHook('actionObjectAddAfter')
&& $this->registerHook('actionObjectCurrencyUpdateAfter')
&& $this->registerHook('displayBackOfficeTop')
&& $this->registerHook('displayBackOfficeHeader');
// New hooks in 1.7
if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
$this->registerHook('displayNav1');
}
}
}
return $success;
}
/**
* Uninstalls the module.
*
* Removes used config values. No need to un-register any hooks,
* as that is handled by the parent class.
*
* @return bool
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @noinspection PhpUnused
*/
public function uninstall()
{
return parent::uninstall()
&& NostoHelperAccount::deleteAll()
&& NostoHelperConfig::purge()
&& NostoCustomerManager::dropTables()
&& NostoAdminTabManager::uninstall();
}
/**
* Get content for displaying message
*
* @return string display content
*/
private function displayMessages()
{
$output = '';
if (($errorMessage = Tools::getValue('oauth_error')) !== false) {
$output .= $this->displayError($this->l($errorMessage));
}
if (($successMessage = Tools::getValue('oauth_success')) !== false) {
$output .= $this->displayConfirmation($this->l($successMessage));
}
foreach (NostoHelperFlash::getList('success') as $flashMessage) {
$output .= $this->displayConfirmation($flashMessage);
}
foreach (NostoHelperFlash::getList('error') as $flashMessage) {
$output .= $this->displayError($flashMessage);
}
if (Shop::getContext() !== Shop::CONTEXT_SHOP) {
$output .= $this->displayError($this->l('Please choose a shop to configure Nosto for.'));
}
if (!Module::isEnabled($this->name)) {
$output .= $this->displayError(
$this->l('Nosto is deactivated for this store view. Please activate it before continuing.')
);
}
return $output;
}
/**
* Renders the module administration form.
* Also handles the form submit action.
*
* @return string The HTML to output.
* @throws \Nosto\NostoException
* @noinspection PhpUnused
*/
public function getContent()
{
$output = $this->displayMessages();
//If scope is not on shop level, skip rendering nosto page
if (Shop::getContext() !== Shop::CONTEXT_SHOP) {
return $output;
}
//if nosto module is inactivated for this shop, skip rendering nosto page
if (!Module::isEnabled($this->name)) {
return $output;
}
$indexController = new NostoIndexController();
$indexController->displaySuccessMessage($this);
$indexController->displayErrorMessage($this);
$smartyMetaData = $indexController->getSmartyMetaData($this);
$this->getSmarty()->assign($smartyMetaData);
$this->getSmarty()->assign(array(
'module_path' => $this->_path
));
$templateFile = 'views/templates/admin/config-bootstrap.tpl';
$output .= $this->display(__FILE__, $templateFile);
return $output;
}
/**
* Layout hook for adding content to the <head> of every page. This hook renders the entire
* client script, the add-to-cart script and some meta tags
*
* @return string The HTML to output
* @throws \Nosto\NostoException
*/
public function hookDisplayHeader()
{
return NostoHeaderContent::get($this);
}
/**
* Backwards compatibility layout hook for adding content to the <head> of every page. This hook
* should not have any logic and should only delegate to another hook.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @see NostoTagging::hookDisplayHeader()
* @noinspection PhpUnused
*/
public function hookHeader()
{
return $this->hookDisplayHeader();
}
/**
* Hook for adding content to the <head> section of the back office HTML pages.
* Also updates exchange rates if needed.
*
* Note: PS 1.5+ only.
*
* Adds Nosto admin tab CSS.
* @noinspection PhpUnused
*/
public function hookDisplayBackOfficeHeader()
{
// In some cases, the controller in the context is actually not an instance of `AdminController`,
// but of `AdminTab`. This class does not have an `addCss` method.
// In these cases, we skip adding the CSS which will only cause the logo to be missing for the
// Nosto menu item in PS >= 1.6.
$ctrl = $this->context->controller;
if ($ctrl instanceof AdminController && method_exists($ctrl, 'addCss')) {
$ctrl->addCss($this->_path . 'views/css/nostotagging-back-office.css');
}
$this->updateExchangeRatesIfNeeded(false);
}
/**
* Layout hook for adding content to the header of every page. This hook renders the entire
* tagging if the tagging wasn't rendered in a previous hook.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws ReflectionException
*/
public function hookDisplayTop()
{
$html = '';
if ($this->topHookExecuted !== true
&& NostoHelperConfig::getNostotaggingRenderPosition() !== NostoHelperConfig::NOSTOTAGGING_POSITION_FOOTER
) {
$html = NostoDefaultTagging::get($this);
$html .= self::dispatchPseudoHooks();
$this->topHookExecuted = true;
}
return $html;
}
/**
* Returns hidden nosto recommendation elements for the current controller.
* These are used as a fallback for showing recommendations if the appropriate hooks are not
* present in the theme. The hidden elements are put into place and shown in the shop with
* JavaScript.
*
* @return string the html.
* @noinspection PhpUnused
*/
public static function dispatchPseudoHooks()
{
$methodName = 'pseudoHookLoadingPage';
$methodName .= str_replace('-', '', NostoHelperController::getControllerName());
if (method_exists(__CLASS__, $methodName)) {
return self::$methodName();
}
// If the current page is not one of the ones we want to show recommendations on, just
// return empty.
return '';
}
/** @noinspection PhpUnused,PhpUnusedPrivateMethodInspection */
private static function pseudoHookLoadingPageIndex()
{
$html = '';
try {
$html = NostoHiddenElement::append('frontpage-nosto-1');
$html .= NostoHiddenElement::append('frontpage-nosto-2');
$html .= NostoHiddenElement::append('frontpage-nosto-3');
$html .= NostoHiddenElement::append('frontpage-nosto-4');
} catch (\Nosto\NostoException $e) {
NostoHelperLogger::error($e);
}
return $html;
}
/** @noinspection PhpUnused,PhpUnusedPrivateMethodInspection */
private static function pseudoHookLoadingPageProduct()
{
$html = '';
try {
$html = NostoHiddenElement::append('nosto-page-product1');
$html .= NostoHiddenElement::append('nosto-page-product2');
$html .= NostoHiddenElement::append('nosto-page-product3');
} catch (\Nosto\NostoException $e) {
NostoHelperLogger::error($e);
}
return $html;
}
/** @noinspection PhpUnused,PhpUnusedPrivateMethodInspection */
private static function pseudoHookLoadingPageOrder()
{
if ((int)Tools::getValue('step', 0) !== 0) {
return '';
}
$html = '';
try {
$html = NostoHiddenElement::append('nosto-page-cart1');
$html .= NostoHiddenElement::append('nosto-page-cart2');
$html .= NostoHiddenElement::append('nosto-page-cart3');
} catch (\Nosto\NostoException $e) {
NostoHelperLogger::error($e);
}
return $html;
}
/** @noinspection PhpUnused */
private static function pseudoHookLoadingPageCategory()
{
$html = '';
try {
$html = NostoHiddenElement::append('nosto-page-category1');
$html .= NostoHiddenElement::append('nosto-page-category2');
} catch (\Nosto\NostoException $e) {
NostoHelperLogger::error($e);
}
return $html;
}
/** @noinspection PhpUnused,PhpUnusedPrivateMethodInspection */
private static function pseudoHookLoadingPageManufacturer()
{
return self::pseudoHookLoadingPageCategory();
}
/** @noinspection PhpUnused,PhpUnusedPrivateMethodInspection */
private static function pseudoHookLoadingPageSearch()
{
$html = '';
try {
$html = NostoHiddenElement::prepend('nosto-page-search1');
$html .= NostoHiddenElement::append('nosto-page-search2');
} catch (\Nosto\NostoException $e) {
NostoHelperLogger::error($e);
}
return $html;
}
private static function pseudoHookLoadingPagePageNotFound()
{
$html = '';
try {
$html = NostoHiddenElement::append('notfound-nosto-1');
$html .= NostoHiddenElement::append('notfound-nosto-2');
$html .= NostoHiddenElement::append('notfound-nosto-3');
} catch (\Nosto\NostoException $e) {
NostoHelperLogger::error($e);
}
return $html;
}
/** @noinspection PhpUnused,PhpUnusedPrivateMethodInspection */
private static function pseudoHookLoadingPage404()
{
return self::pseudoHookLoadingPagePageNotFound();
}
/** @noinspection PhpUnused,PhpUnusedPrivateMethodInspection */
private static function pseudoHookLoadingPageOrderConfirmation()
{
$html = '';
try {
$html = NostoHiddenElement::append('thankyou-nosto-1');
$html .= NostoHiddenElement::append('thankyou-nosto-2');
} catch (\Nosto\NostoException $e) {
NostoHelperLogger::error($e);
}
return $html;
}
/**
* Modern layout hook for adding content to the top of every page in displayNav1. This hooks is
* newer 1.7 hook that does the same as the top hook. This hook should not have any logic and
* should only delegate to another hook.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws ReflectionException
* @since Prestashop 1.7.0.0
* @noinspection PhpUnused
*/
public function hookDisplayNav1()
{
return $this->hookDisplayTop();
}
/**
* Backwards compatibility layout hook that renders content in the header of every page. This
* hook should not have any logic and should only delegate to another hook.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws ReflectionException
* @see NostoTagging::hookDisplayTop()
* @noinspection PhpUnused
*/
public function hookTop()
{
return $this->hookDisplayTop();
}
/**
* Layout hook for adding content to the footer of every page. This hook renders a recommendation
* element and also renders the entire tagging if the tagging wasn't rendered in a previous
* hook.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws ReflectionException
*/
public function hookDisplayFooter()
{
$html = '';
if (NostoHelperConfig::getNostotaggingRenderPosition() === NostoHelperConfig::NOSTOTAGGING_POSITION_FOOTER) {
$html = NostoDefaultTagging::get($this);
$html .= self::dispatchPseudoHooks();
}
$html .= NostoRecommendationElement::get("nosto-page-footer");
return $html;
}
/**
* Backwards compatibility layout hook for adding content to the footer of every page. This hook
* should not have any logic and should only delegate to another hook.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws ReflectionException
* @see NostoTagging::hookDisplayFooter()
* @noinspection PhpUnused
*/
public function hookFooter()
{
return $this->hookDisplayFooter();
}
/**
* Layout hook for adding content to the left column of every page. This hook renders a single
* recommendation element. This hook is extremely theme-dependant and may not always exist.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @noinspection PhpUnused
*/
public function hookDisplayLeftColumn()
{
return NostoRecommendationElement::get("nosto-column-left");
}
/**
* Backwards compatibility layout hook for adding content to the left column of every page.
* This hook should not have any logic and should only delegate to another hook.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @see NostoTagging::hookDisplayRightColumn()
* @noinspection PhpUnused
*/
public function hookLeftColumn()
{
return $this->hookDisplayLeftColumn();
}
/**
* Layout hook for adding content to the right column of every page. This hook renders a single
* recommendation element. This hook is extremely theme-dependant and may not always exist.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
*/
public function hookDisplayRightColumn()
{
return NostoRecommendationElement::get("nosto-column-right");
}
/**
* Backwards compatibility layout hook for adding content to the right column of every page.
* This hook should not have any logic and should only delegate to another hook.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @see NostoTagging::hookDisplayRightColumn()
* @noinspection PhpUnused
*/
public function hookRightColumn()
{
return $this->hookDisplayRightColumn();
}
/**
* Layout hook for adding content below the product description on the product page. This hook
* renders three recommendation elements. The product tagging is omitted from here and instead
* rendered along with the rest of the tagging to keep all the tagging consolidated.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
*/
public function hookDisplayFooterProduct()
{
$html = '';
$html .= NostoRecommendationElement::get("nosto-page-product1");
$html .= NostoRecommendationElement::get("nosto-page-product2");
$html .= NostoRecommendationElement::get("nosto-page-product3");
return $html;
}
/**
* Backwards compatibility layout hook for adding content below the product description on the
* product page. This hook should not have any logic and should only delegate to another hook.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @see NostoTagging::hookDisplayFooterProduct()
* @noinspection PhpUnused
*/
public function hookProductFooter()
{
return $this->hookDisplayFooterProduct();
}
/**
* Layout hook for adding content to the cart page below the itemised cart listing. This hooks
* renders three recommendation elements on the cart page and also updates the customer link
* table.
*
* @return string The HTML to output
* @throws \Nosto\NostoException
*/
public function hookDisplayShoppingCartFooter()
{
$html = '';
$html .= NostoRecommendationElement::get("nosto-page-cart1");
$html .= NostoRecommendationElement::get("nosto-page-cart2");
$html .= NostoRecommendationElement::get("nosto-page-cart3");
return $html;
}
/**
* Backwards compatibility layout hook for adding content to the cart page below the itemised
* cart listing. This hook should not have any logic and should only delegate to another hook.
*
* @see NostoTagging::hookDisplayShoppingCartFooter()
* @return string The HTML to output
* @throws \Nosto\NostoException
* @noinspection PhpUnused
*/
public function hookShoppingCart()
{
return $this->hookDisplayShoppingCartFooter();
}
/**
* Layout hook for adding content to search page above the category items list. This hook renders
* a single recommendation element.
* <br />
* Please note that in order for this hook to be executed, it will have to be added to the
* theme category.tpl file.
*
* {hook h='displayCategoryTop'}
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @noinspection PhpUnused
*/
public function hookDisplayCategoryTop()
{
return NostoRecommendationElement::get("nosto-page-category1");
}
/**
* Layout hook for adding content to search page below the category items list. This hook renders
* a single recommendation element.
* <br />
* Please note that in order for this hook to be executed, it will have to be added to the
* theme category.tpl file.
*
* {hook h='displayCategoryFooter'}
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @noinspection PhpUnused
*/
public function hookDisplayCategoryFooter()
{
return NostoRecommendationElement::get("nosto-page-category2");
}
/**
* Layout hook for adding content to search page above the search result list. This hook renders
* a single recommendation element.
* <br />
* Please note that in order for this hook to be executed, it will have to be added to the
* theme search.tpl file.
*
* {hook h='displaySearchTop'}
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @noinspection PhpUnused
*/
public function hookDisplaySearchTop()
{
return NostoRecommendationElement::get("nosto-page-search1");
}
/**
* Layout hook for adding content to search page below the search result list. This hook renders
* a single recommendation element.
* <br />
* Please note that in order for this hook to be executed, it will have to be added to the
* theme search.tpl file.
*
* {hook h='displaySearchFooter'}
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @noinspection PhpUnused
*/
public function hookDisplaySearchFooter()
{
return NostoRecommendationElement::get("nosto-page-search2");
}
/**
* Layout hook for updating the customer link table with the Prestashop customer id and the Nosto
* customer id. This hook doesn't render anything as the cart tagging is rendered along with the
* other tagging while the recommendation elements are at the bottom of the page. No recommendation
* elements are rendered here as it is too intrusive.
*/
public function hookDisplayPaymentTop()
{
try {
NostoCustomerManager::updateNostoId();
} catch (PrestaShopDatabaseException $e) {
NostoHelperLogger::error($e);
}
}
/**
* Backwards compatibility layout hook that renders content above the payment page. This
* hook should not have any logic and should only delegate to another hook.
*
* @see NostoTagging::hookDisplayPaymentTop()
* @noinspection PhpUnused
*/
public function hookPaymentTop()
{
$this->hookDisplayPaymentTop();
}
/**
* Observer hook that is called when the order's status is updated. This hook sends an order
* order confirmation to Nosto via the API.
*
* This is a fallback for the regular order tagging on the "order confirmation page", as there
* are cases when the customer does not get redirected back to the shop after the payment is
* completed.
*
* @param array $params the observer parameters, one of which contains the order model
* @noinspection PhpUnused
*/
public function hookActionOrderStatusPostUpdate(array $params)
{
$operation = new NostoOrderService();
$operation->send($params);
}
/**
* Backwards compatibility observer hook that is called when an order's status is updated. This
* hook should not have any logic and should only delegate to another hook.
*
* @see NostoTagging::hookActionOrderStatusPostUpdate()
* @param array $params the observer parameters, one of which contains the order model
* @noinspection PhpUnused
*/
public function hookPostUpdateOrderStatus(array $params)
{
$this->hookActionOrderStatusPostUpdate($params);
}
/**
* Cart item quantity update event. In this hook it send a cart updated event to nosto
* or set a cookie to inform javascript about the cart update
*
* @param array $params the observer parameters, contains the added product information
* @noinspection PhpUnused
*/
public function hookActionCartUpdateQuantityBefore(array $params)
{
try {
$service = new NostoCartService();
$service->cartItemQuantityChanged($params);
} catch (Exception $e) {
NostoHelperLogger::error($e);
}
}
/**
* Cart item quantity update event. In this hook it send a cart updated event to nosto
* or set a cookie to inform javascript about the cart update.
* This is for the prestashop 1.6. This hook should
* not have any logic and should only delegate to another hook.
*
* @param array $params the observer parameters, contains the added product information
* @noinspection PhpUnused
*/
public function hookActionBeforeCartUpdateQty(array $params)
{
$this->hookActionCartUpdateQuantityBefore($params);
}
/**
* Cart updated event. In this hook it send a cart updated event to nosto
* or set a cookie to inform javascript about the cart update.
*
* @param array $params the observer parameters, contains the updated cart model
* @noinspection PhpUnused
*/
public function hookActionCartSave(array $params)
{
try {
$service = new NostoCartService();
$service->cartUpdated($params);
} catch (Exception $e) {
NostoHelperLogger::error($e);
}
}
/**
* Customer created event handler. It works if the customer was created on front end, not from backend.
* The customer's newsletter subscription status could not be set in the backend.
* @param array $params the observer parameters
* @noinspection PhpUnused
*/
public function hookActionCustomerAccountAdd(array $params)
{
try {
if (isset($params['newCustomer']) && $params['newCustomer'] instanceof Customer) {
$service = new NostoCustomerService();
$service->customerUpdated($params['newCustomer']);
}
} catch (Exception $e) {
NostoHelperLogger::error($e);
}
}
/**
* Customer updated event handler. It works if the customer was updated on front end, not from backend.
* The customer's newsletter subscription status could not be changed in the backend.
* @param array $params the observer parameters
* @noinspection PhpUnused
*/
public function hookActionCustomerAccountUpdate(array $params)
{
try {
if (isset($params['customer']) && $params['customer'] instanceof Customer) {
$service = new NostoCustomerService();
$service->customerUpdated($params['customer']);
}
} catch (Exception $e) {
NostoHelperLogger::error($e);
}
}
/**
* Layout hook for adding content to the home page. This hooks renders four recommendation
* elements on the front page
*
* @return string The HTML to output
* @throws \Nosto\NostoException
* @noinspection PhpUnused
*/
public function hookDisplayHome()
{
$html = '';
$html .= NostoRecommendationElement::get("frontpage-nosto-1");
$html .= NostoRecommendationElement::get("frontpage-nosto-2");
$html .= NostoRecommendationElement::get("frontpage-nosto-3");
$html .= NostoRecommendationElement::get("frontpage-nosto-4");
return $html;
}
/**
* Backwards compatibility layout hook for adding content to the home page. This hook should
* not have any logic and should only delegate to another hook.
*
* @see NostoTagging::hookDisplayHome()
* @return string The HTML to output
* @throws \Nosto\NostoException
* @noinspection PhpUnused
*/
public function hookHome()
{
return $this->hookDisplayHome();
}
/**
* Hook that is fired after a object has been updated in the database. This hook intercepts all
* object modifications but the service filters out non-product events i.e. events whose
* parameter named `object` don't have a product object.
*
* @param array $params the observer parameters, one of which contains the mutated model
* @noinspection PhpUnused
*/
public function hookActionObjectUpdateAfter(array $params)
{
try {
$operation = new NostoProductService();
$operation->upsert($params);
} catch (Exception $e) {
NostoHelperLogger::error($e);
}
}
/**
* Hook that is fired after a object has been deleted in the database. This hook intercepts all
* object deletions but the service filters out non-product events i.e. events whose
* parameter named `object` don't have a product object.
*
* @param array $params the observer parameters, one of which contains the mutated model
* @noinspection PhpUnused
*/
public function hookActionObjectDeleteAfter(array $params)