-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelloprestashopproducts.php
127 lines (111 loc) · 3.53 KB
/
helloprestashopproducts.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
<?php
require_once __DIR__.'/vendor/autoload.php';
use PsProducts\Hooks as ProductHooks;
use PsProducts\AlternativeDescription;
use PsProducts\ProductsCollection;
/*
This project is based on the [Friends of Presta/products](https://github.com/friends-of-presta/products) module.
Thanks to [Friends of Presta/Mickaël Andrieu](https://github.com/friends-of-presta).
*/
/**
* Module to present how Prestashop developers
* can customize Product pages.
*/
class HelloPrestaShopProducts extends Module
{
/**
* @var array list of available Product hooks.
*/
private $productHooks;
public function __construct()
{
$this->name = 'helloprestashopproducts';
$this->version = '1.0.0';
$this->author = 'PHP-Prefixer';
parent::__construct();
$this->displayName = 'Hello PrestaShop Products';
$this->description = 'Hello PrestaShop Products module';
$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');
}
}