Я могу добавить поля в БД и во внешнем интерфейсе, но не могу найти обычный admincustomercontroller.php. Кто-нибудь знает, как поступить?
Я пытался следовать руководству Symfony по этой ссылке: Добавить настраиваемое поле в категорию Prestashop 1.7.6 с помощью модуля. Как сохранить в базе данных?
класс Customercustomfields extends Module {protected $ config_form = false;
public function __construct()
{
$this->name = 'customercustomfields';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'DB';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
/*$this->displayName = $this->l('Category Custom Fields');
$this->description = $this->l('Add custom fields to category');*/
$this->displayName = $this->l('SDI');
$this->description = $this->l('SDI');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
public function install()
{
if (!parent::install()
// Install Sql du module
|| !$this->_installSql()
//Installation des hooks
|| !$this->registerHook('actionAdminCustomersControllerSaveAfter')
|| !$this->registerHook('actionAdminCustomersFormModifier')
) {
return false;
}
return true;
}
public function hookActionCustomFormBuilderModifier(array $params)
{
//Récupération du form builder
/** @var \Symfony\Component\Form\FormBuilder $formBuilder */
$formBuilder = $params['form_builder'];
//Ajout de notre champ spécifique
$formBuilder->add('color',
\Symfony\Component\Form\Extension\Core\Type\TextType::class,
[
'label' => $this->l('SDI'), //Label du champ
'required' => false, //Requis ou non
'constraints' => [ //Contraintes du champs
new \Symfony\Component\Validator\Constraints\Length([
'max' => 20,
'maxMessage' => $this->l('Max caracters allowed : 20'),
]),
],
'data' => '' //Valeur du champ
]
);
$formBuilder->setData($params['data'], $params);
}
public function hookActionAfterCreateCategoryFormHandler(array $params)
{
$this->updateData($params['form_data'], $params);
}
public function hookActionAfterUpdateCategoryFormHandler(array $params)
{
$this->updateData($params['form_data'], $params);
}
//params not well used but for examples
protected function updateData(array $data, $params)
{
$cat = new Customer((int)$params['id']);
$cat->SDI= $data['SDI'];
$cat->update();
/*$insertData = array(
'id_category' => (int)$params['id'],
'id_lang' => (int)$this->context->language->id,
'color' => $data['color'],
);
//Update database
Db::getInstance()->insert( "ps_category_lang ", $insertData);*/
}
}