-
Notifications
You must be signed in to change notification settings - Fork 0
/
combinationeditor.php
107 lines (91 loc) · 3.19 KB
/
combinationeditor.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
<?php
/**
* 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
*
* @author Karlis Suvi
* @copyright 2022 Karlis Suvi
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class Combinationeditor extends Module
{
public function __construct()
{
$this->name = 'combinationeditor';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'Karlis Suvi';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->trans('Combination Attributes Editor', [], 'Modules.Combinationeditor.Admin');
$this->description = $this->trans('Change combination\'s attributes even after creation.', [], 'Modules.Combinationeditor.Admin');
$this->confirmUninstall = $this->trans('Are you sure you want to uninstall this module?', [], 'Modules.Combinationeditor.Admin');
$this->ps_versions_compliancy = ['min' => '1.7', 'max' => _PS_VERSION_];
}
/**
* @return bool
*/
public function isUsingNewTranslationSystem()
{
return true;
}
public function install()
{
return parent::install() &&
$this->registerHook('actionAdminControllerSetMedia') &&
$this->registerHook('displayAdminProductsCombinationBottom');
}
public function uninstall()
{
return parent::uninstall();
}
/**
* Add the CSS & JavaScript files you want to be loaded in the BO.
*/
public function hookActionAdminControllerSetMedia()
{
if (!$this->isSymfonyContext()) {
return;
}
$requestStack = $this->get('request_stack');
if ($requestStack === false) {
return;
}
$currentRequest = $requestStack->getCurrentRequest();
if ($currentRequest === null || $currentRequest->get('_route') !== 'admin_product_form') {
return;
}
$this->context->controller->addJS(
"{$this->getPathUri()}views/js/combinationeditor.js"
);
}
/**
* Displays attributes form under combination settings.
*
* @param array $params
*/
public function hookDisplayAdminProductsCombinationBottom($params)
{
$formBuilder = $this->get('prestashop.module.combinationeditor.form.identifiable_object.builder.combination_attributes_form_builder');
$twig = $this->get('twig');
// In case form builder or Twig service doesn't exist, don't render anything
if ($formBuilder === false || $twig === false) {
return '';
}
$form = $formBuilder->getFormFor((int) $params['id_product_attribute']);
return $twig->render(
'@Modules/combinationeditor/views/templates/admin/attributes_manager.html.twig',
[
'attributesForm' => $form->createView(),
'idProductAttribute' => (int) $params['id_product_attribute'],
]
);
}
}