我能够在数据库和前端中添加字段,但是找不到通常的admincustomercontroller.php。有人知道如何进行吗?
我尝试在此链接上关注symfony教程: Add custom field in Prestashop 1.7.6 category with a module. How to save in database?
类Customercustomfields扩展模块 { 保护$ 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);*/
}
}