27 minutes ago, ventura said:Try it with something like that, new created name custom_boolean
Create a class override in module_name/override/classes/Category.php
<?php class Category extends CategoryCore { public $custom_boolean; public function __construct($id_category = null, $id_lang = null, $id_shop = null){ self::$definition['fields']['custom_boolean'] =['type' => self::TYPE_BOOL, 'validate' => 'isBool']; parent::__construct($id_category, $id_lang, $id_shop); } }
Actiion hooks something like that
public function hookActionCategoryFormBuilderModifier(array $params) { $shopId = $this->context->shop->id; $categoryId = $params['id']; $langId = $this->context->language->id; $category = new Category( $categoryId, $langId, $shopId); $formBuilder = $params['form_builder']; $formBuilder->add( 'custom_boolean', SwitchType::class, [ 'label' => $this->l('Turn on or off'), 'required' => false, 'choices' => [ $this->l('Disabled') => 0, $this->l('Enabled') => 1, ], ] ); $params['data']['custom_boolean'] = $category->custom_boolean; $formBuilder->setData($params['data']); } public function hookActionAfterUpdateCategoryFormHandler(array $params) { $this->updateData($params); } public function hookActionAfterCreateCategoryFormHandler(array $params) { $this->updateData($params); } private function updateData(array $params) { $formData = $params['form_data']; $cat = new Category((int)$params['id']); $cat->custom_boolean = $formData['custom_boolean']; $cat->update(); }
I am halfway there. With this code I get the correct value from the DB but when I change the value I and click on Save I get an error: An error occurred while editing the category.
When I turned on debug mode I get this error An unexpected error occurred. [Symfony\Component\Debug\Exception\ContextErrorException code 0]: Notice: Undefined property: Category::$custom_boolean