-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendinblueresttracker.php
123 lines (103 loc) · 4.13 KB
/
sendinblueresttracker.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
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* 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 license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
$autoloadPath = dirname(__FILE__) . '/vendor/autoload.php';
if (file_exists($autoloadPath)) {
require_once $autoloadPath;
}
class SendinblueRestTracker extends Module
{
public function __construct()
{
$this->name = 'sendinblueresttracker';
$this->tab = 'advertising_marketing';
$this->version = '2.0.0';
$this->author = 'Novanta';
parent::__construct();
$this->displayName = $this->trans('Sendinblue REST tracker', [], 'Modules.Sendinblueresttracker.Admin');
$this->description = $this->trans('Adding Sendinblue Tracker to track some custom event', [], 'Modules.Sendinblueresttracker.Admin');
$this->ps_versions_compliancy = [
'min' => '8.0.0',
'max' => _PS_VERSION_,
];
}
public function install()
{
// if(!$this->get('prestashop.module.manager')->isInstalled('sendinblue')) {
// return false;
// }
return parent::install()
&& $this->registerHook('actionOrderHistoryAddAfter')
&& $this->registerHook('displayHeader');
}
public function hookActionOrderHistoryAddAfter(array $params)
{
$order_history = $params['order_history'];
$order = new Order($order_history->id_order);
if ($order) {
$customer = $order->getCustomer();
$eventdata = $this->get('Novanta\Sendinblue\Service\RestTracker')->getOrderEventData($order);
$this->get('Novanta\Sendinblue\Service\RestTracker')->trackEvent($customer, 'order_status_update', $eventdata);
}
}
public function hookDisplayHeader(array $params)
{
if ($this->context->controller instanceof OrderController) {
if ($this->isFirstCheckoutStep()) {
$customer = $this->context->customer;
$eventdata = $this->get('Novanta\Sendinblue\Service\RestTracker')->getCartEventData($this->context->cart);
$this->get('Novanta\Sendinblue\Service\RestTracker')->trackEvent($customer, 'initiate_checkout', $eventdata);
}
}
}
private function isFirstCheckoutStep()
{
if (!$this->context->controller instanceof OrderController) {
return false;
}
$checkoutSteps = $this->getAllOrderSteps();
/* Get the checkoutPaymentKey from the $checkoutSteps array */
foreach ($checkoutSteps as $stepObject) {
if ($stepObject instanceof CheckoutAddressesStep) {
return (bool) $stepObject->isCurrent();
}
}
return false;
}
private function getAllOrderSteps()
{
$isPrestashop177 = version_compare(_PS_VERSION_, '1.7.7.0', '>=');
if (true === $isPrestashop177) {
return $this->context->controller->getCheckoutProcess()->getSteps();
}
/* Reflect checkoutProcess object */
$reflectedObject = (new ReflectionObject($this->context->controller))->getProperty('checkoutProcess');
$reflectedObject->setAccessible(true);
/* Get Checkout steps data */
$checkoutProcessClass = $reflectedObject->getValue($this->context->controller);
return $checkoutProcessClass->getSteps();
}
public function isUsingNewTranslationSystem()
{
return true;
}
}