-
Notifications
You must be signed in to change notification settings - Fork 11
/
products.php
130 lines (115 loc) · 3.54 KB
/
products.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
<?php
/**
* 2007-2018 Friends of PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0).
* It is also available through the world-wide-web at this URL: https://opensource.org/licenses/AFL-3.0
*/
require_once __DIR__.'/vendor/autoload.php';
use PsDay\Hooks as ProductHooks;
use PsDay\AlternativeDescription;
use PsDay\ProductsCollection;
/**
* Module to present how Prestashop developers
* can customize Product pages.
*/
class Products extends Module
{
/**
* @var array list of available Product hooks.
*/
private $productHooks;
public function __construct()
{
$this->name = 'products';
$this->version = '1.0.0';
$this->author = 'Mickaël Andrieu';
parent::__construct();
$this->displayName = 'Products';
$this->description = 'Module to demonstrate how to customize Product pages';
$this->ps_versions_compliancy = [
'min' => '1.7.4.0',
'max' => _PS_VERSION_,
];
$this->productHooks = array_merge(ProductHooks::PRODUCT_LIST_HOOKS, ProductHooks::PRODUCT_FORM_HOOKS);
}
/**
* Module installation.
*
* @return bool Success of the installation
*/
public function install()
{
return parent::install()
&& AlternativeDescription::addToProductTable()
&& $this->registerHook($this->productHooks)
;
}
/**
* Uninstall the module.
*
* @return bool Success of the uninstallation
*/
public function uninstall()
{
return parent::uninstall()
&& AlternativeDescription::removeToProductTable()
;
}
/**
* Display "alternative" in Product page.
* @param type $hookParams
* @return string
*/
public function hookDisplayAdminProductsMainStepLeftColumnMiddle($hookParams)
{
$productId = $hookParams['id_product'];
$formFactory = $this->get('form.factory');
$twig = $this->get('twig');
$form = AlternativeDescription::addToForm($productId, $formFactory);
// You don't need to design your form, call only form_row(my_field) in
// your template.
return AlternativeDescription::setTemplateToProductPage($twig, $form);
}
/**
* Add the field "alternative_description to Product table.
*/
public function hookActionDispatcherBefore()
{
AlternativeDescription::addToProductDefinition();
}
/**
* Manage the list of product fields available in the Product Catalog page.
* @param type $hookParams
*/
public function hookActionAdminProductsListingFieldsModifier(&$hookParams)
{
$hookParams['sql_select']['alternative_description'] = [
'table' => 'p',
'field' => 'alternative_description',
'filtering' => "LIKE '%%%s%%'",
];
}
/**
* Manage the list of products available in the Product Catalog page.
* @param type $hookParams
*/
public function hookActionAdminProductsListingResultsModifier(&$hookParams)
{
$hookParams['products'] = ProductsCollection::make($hookParams['products'])
->sortBy('alternative_description')
->all()
;
}
/**
* Manage the information in a specific tab of Product Page.
* @param type $hookParams
* @return string
*/
public function hookDisplayAdminProductsExtra(&$hookParams)
{
return $this->get('twig')->render('@PrestaShop/Products/module_panel.html.twig');
}
}