-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfbsample_addcolumninprodlist.php
113 lines (102 loc) · 3.56 KB
/
fbsample_addcolumninprodlist.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
<?php
/**
* 2007-2018 Frédéric BENOIST
*
* 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 license@prestashop.com so we can send you a copy immediately.
*
* @author Frédéric BENOIST
* @copyright 2013-2018 Frédéric BENOIST <https://www.fbenoist.com/>
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class FbSample_AddColumnInProdList extends Module
{
public function __construct()
{
$this->name = 'fbsample_addcolumninprodlist';
$this->author = 'Frédéric BENOIST';
$this->version = '1.0.0';
$this->need_instance = 0;
$this->bootstrap = true;
$this->tab = 'others';
parent::__construct();
$this->displayName = $this->l('Add column in product list');
$this->ps_versions_compliancy = array(
'min' => '1.7.5',
'max' => _PS_VERSION_
);
$this->description = $this->l(
'Sample PrestaShop 1.7 module, add column in product list.'
);
}
public function install()
{
if (!parent::install()
|| !$this->registerHook('displayAdminCatalogProductHeader')
|| !$this->registerHook('displayAdminCatalogProductFilter')
|| !$this->registerHook('displayAdminCatalogListingProductFields')
|| !$this->registerHook('actionAdminProductsListingFieldsModifier')
) {
return false;
}
return true;
}
public function hookDisplayAdminCatalogProductHeader($params)
{
return $this->display(
__FILE__,
'views/templates/hook/product_list_header.tpl'
);
}
public function hookDisplayAdminCatalogProductFilter($params)
{
$manufacturers = Manufacturer::getManufacturers();
$this->context->smarty->assign([
'filter_column_manufacturer' => Tools::getValue('filter_column_manufacturer', ''),
'manufacturers' => $manufacturers
]);
return $this->display(
__FILE__,
'views/templates/hook/product_list_filter.tpl'
);
}
public function hookDisplayAdminCatalogListingProductFields($params)
{
$this->context->smarty->assign(
'product',
$params['product']
);
return $this->display(
__FILE__,
'views/templates/hook/product_list_fields.tpl'
);
}
public function hookActionAdminProductsListingFieldsModifier($params)
{
// Manufacturer
$params['sql_select']['manufacturer'] = [
'table' => 'm',
'field' => 'name',
'filtering' => \PrestaShop\PrestaShop\Adapter\Admin\AbstractAdminQueryBuilder::FILTERING_LIKE_BOTH
];
$params['sql_table']['m'] = [
'table' => 'manufacturer',
'join' => 'LEFT JOIN',
'on' => 'p.`id_manufacturer` = m.`id_manufacturer`',
];
$manufacturerFilter = Tools::getValue('filter_column_manufacturer', false);
if ($manufacturerFilter && $manufacturerFilter != '') {
$params['sql_where'][] .= " p.id_manufacturer = ".$manufacturerFilter;
}
}
}