Prestashop 1.6 - 将自定义字段添加到类别 [英] Prestashop 1.6 - Add custom field to category

查看:80
本文介绍了Prestashop 1.6 - 将自定义字段添加到类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何向类别添加自定义字段以及如何在后台进行编辑(在描述字段下).我想添加的字段是名称 description_long

I would like to know how I can add a custom field to a category and how I can edit in the back office (under the description field). the field I would like to add is name description_long

字段类型为TEXT

我已经覆盖了我的前台,并且我的领域显示得很好.

I already have overwritten my Front office , and my field is well displayed .

覆盖\classes\Category.php

<?php 

class Category extends CategoryCore
{

    public $description_long;

    /**
     * @see ObjectModel::$definition
     */
    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' => 128),
            'link_rewrite' =>       array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128),
            'description' =>        array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
            'description_long' =>   array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'), // CUSTOM FIELD
            '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),
        ),
    );
}

没有找到任何walktrough,有人可以帮忙吗?

Did not find any walktrough, can anyone help ?

推荐答案

对于任何在这里挣扎的人来说,这是一个完整的答案:

要将新的 description_long 字段添加到 Prestashop 类别中的类别,您需要 3 个步骤:

To Add a new description_long field to a category in Prestashop Category you need 3 steps:

  1. 更新数据库

在category_lang表中添加你的description_long字段,可以模仿description列的特征

Add your field named description_long to the category_lang table, you can mimic the description column characteristics

  1. 覆盖类别类

使用以下代码在此处创建一个文件/override/classes/Category.php:

Create a file here /override/classes/Category.php with this code:

class Category extends CategoryCore
{

    public $description_long;

    public function __construct($id_category = null, $id_lang = null, $id_shop = null){
        self::$definition['fields']['description_long'] = array('type' => self::TYPE_HTML, 'lang' => true);
        parent::__construct($id_category, $id_lang, $id_shop);
    }

}

  1. 覆盖 AdminCategoriesControllerCore 类

在此处创建一个文件/override/controllers/admin/AdminCategoriesController.php 使用以下代码:

Create a file here /override/controllers/admin/AdminCategoriesController.php with this code :

class AdminCategoriesController extends AdminCategoriesControllerCore{


    public function renderForm()
    {
        $this->fields_form_override =array(
            array(
                'type' => 'textarea',
                'label' => $this->l('Description long'),
                'name' => 'description_long',
                'lang' => true,
                'autoload_rte' => true,
                'hint' => $this->l('Invalid characters:').' <>;=#{}',
            ),
        );

        return parent::renderForm();
    }
}

这篇关于Prestashop 1.6 - 将自定义字段添加到类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆