-
Notifications
You must be signed in to change notification settings - Fork 1
/
customers.php
executable file
·118 lines (97 loc) · 3.31 KB
/
customers.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
<?php
require_once __DIR__.'/vendor/autoload.php';
use PrestaShop\PrestaShop\Core\Grid\Definition\GridDefinitionInterface;
use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
use PrestaShop\PrestaShop\Core\Grid\Filter\FilterCollection;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\BadgeColumn;
class customers extends Module
{
/**
* In constructor we define our module's meta data.
* It's better tot keep constructor (and main module class itself) as thin as possible
* and do any processing in controller.
*/
public function __construct()
{
$this->name = 'customers';
$this->version = '1.0.0';
$this->author = 'Mickaël Andrieu';
$this->need_instance = 0;
parent::__construct();
$this->displayName = 'Enhanced customers module';
}
/**
* Install module and register hooks to allow grid modification.
*
* @return bool
*/
public function install()
{
$installStatus = parent::install() &&
$this->registerHook('actionCustomerGridDefinitionModifier') &&
$this->registerHook('actionCustomerGridQueryBuilderModifier')
;
Tools::clearSf2Cache();
return $installStatus;
}
/**
* Install module and register hooks to allow grid modification.
*
* @return bool
*/
public function uninstall()
{
$uninstallStatus = parent::uninstall() &&
$this->unregisterHook('actionCustomerGridDefinitionModifier') &&
$this->unregisterHook('actionCustomerGridQueryBuilderModifier')
;
Tools::clearSf2Cache();
return true;
}
/**
* Hooks allows to modify Logs grid definition.
* This hook is a right place to add/remove columns or actions (bulk, grid).
*
* @param array $params
*/
public function hookActionCustomerGridDefinitionModifier(array $params)
{
/** @var GridDefinitionInterface $definition */
$definition = $params['definition'];
/** @var ColumnCollection */
$columns = $definition->getColumns();
$columns->remove('social_title')
->remove('active')
->remove('optin')
->remove('total_spent')
;
$nbOrders = (new DataColumn('nb_orders'))
->setName($this->trans('Orders', [], 'Admin.Global'))
->setOptions([
'field' => 'nb_orders',
])
;
$sales = (new BadgeColumn('total_spent'))
->setName($this->trans('Sales', [], 'Admin.Global'))
->setOptions([
'field' => 'total_spent',
'empty_value' => '--',
]);
$columns->addAfter('newsletter', $nbOrders);
$columns->addAfter('nb_orders', $sales);
/** @var FilterCollection $filters */
$filters = $definition->getFilters();
$filters->remove('social_title')
->remove('active')
->remove('optin')
;
}
public function hookActionCustomerGridQueryBuilderModifier(array $params)
{
$searchQueryBuilder = $params['search_query_builder'];
$searchQueryBuilder->addSelect('COUNT(o.id_order) as nb_orders')
->from('ps_orders o')
;
}
}