Frenchy Posted May 15, 2018 Share Posted May 15, 2018 (edited) I am trying to add a editable field for Category in Prestashop 1.7 I'm already do this : Insert text_SEO in Database override/classes/Category.php <?php class Category extends CategoryCore { public $text_SEO; // My Custom field public static $definition = array( 'table' => 'category', 'primary' => 'id_category', 'multilang' => true, 'multilang_shop' => true, 'fields' => array( 'nleft' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'nright' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'level_depth' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true), 'id_parent' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'id_shop_default' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'is_root_category' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'position' => array('type' => self::TYPE_INT), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), // Lang fields 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64), 'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 64), 'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'), 'text_SEO' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'), 'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128), 'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), 'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255), ), ); } override/controllers/admin/AdminCategoriesController.php class AdminCategoriesController extends AdminCategoriesControllerCore { public function renderForm() { $this->fields_form_override =array( array( 'type' => 'textarea', 'label' => $this->l('Text SEO'), 'name' => 'text_SEO', 'lang' => true, 'autoload_rte' => true, 'hint' => $this->l('Invalid characters:').' <>;=#{}', ), ); return parent::renderForm(); } } How can I display the areatext ? Thank you ! Edited May 15, 2018 by Frenchy (see edit history) Link to comment Share on other sites More sharing options...
faca5 Posted January 23, 2020 Share Posted January 23, 2020 Hello. This code work with 1.7.6.2? I have added both files, add fields in table "category" and removed cache. Still not appear. Link to comment Share on other sites More sharing options...
pixon_88 Posted April 16, 2020 Share Posted April 16, 2020 On 1/23/2020 at 2:32 PM, faca5 said: Hello. This code work with 1.7.6.2? I have added both files, add fields in table "category" and removed cache. Still not appear. Me too, i do that, and don't work for me... BBDD OK. TPL OK. But i can't edit this in control panel. Link to comment Share on other sites More sharing options...
faca5 Posted April 16, 2020 Share Posted April 16, 2020 (edited) Hello. This code is not for 1.7.6.x. We have already solved. Example of code for 1.7.6.x, Category Page with new field (choices): public function hookActionCategoryFormBuilderModifier(array $params) { $formBuilder = $params['form_builder']; $formBuilder->add('ID_MODULE', ChoiceType::class, [ 'label' => $this->getTranslator()->trans('YOUR FIELD NAME', [], 'Modules.MODULE'), 'required' => false, 'choices' => [ ... ], ]); $category_id = $params['id']; $params['data']['ID_MODULE'] = $this->getCategoryBolhaId($category_id); $formBuilder->setData($params['data']); } Edited April 16, 2020 by faca5 (see edit history) Link to comment Share on other sites More sharing options...
sbonet Posted April 16, 2020 Share Posted April 16, 2020 Hello, How do you later show the value on the front page? Can you help me please? Thanks! Link to comment Share on other sites More sharing options...
faca5 Posted April 17, 2020 Share Posted April 17, 2020 Something like that?! $categories_list = Category::getCategories(); $categories = array(); foreach($categories_list as $key => $values) { foreach($values as $key => $value) { foreach($value as $k => $v) { if($v['YOUR_ID']) { $categories[$v['id_category']] = $v['YOUR_ID']; } } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now