-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathkrona.php
72 lines (66 loc) · 1.73 KB
/
krona.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
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class PriceAlertKrona
{
const ACTION_PRICEALERT_CREATED = 'pricealert_created';
/**
* @return array[]
*/
public static function getActions()
{
return [
self::ACTION_PRICEALERT_CREATED => [
'title' => 'Price alert created',
'message' => 'You received {points} points for creating price alert',
]
];
}
/**
* @param array $data
*
* @return void
* @throws PrestaShopException
*/
public static function priceAlertCreated($data)
{
self::triggerAction(self::ACTION_PRICEALERT_CREATED, self::getProductLink($data['id_product']));
}
/**
* @param int $productId
*
* @return string|null
* @throws PrestaShopException
*/
private static function getProductLink($productId)
{
$productId = (int)$productId;
if ($productId) {
return \Context::getContext()->link->getProductLink($productId);
}
return null;
}
/**
* @param string $action
* @param string $url
*
* @return void
* @throws PrestaShopException
*/
private static function triggerAction($action, $url = null)
{
$customer = \Context::getContext()->customer;
if ($customer->isLogged() && array_key_exists($action, self::getActions())) {
$data = [
'module_name' => 'pricealert',
'action_name' => $action,
'id_customer' => (int)$customer->id
];
if (!is_null($url)) {
$data['action_url'] = $url;
}
\Hook::exec('actionExecuteKronaAction', $data);
}
}
}