php - Prestashop 1.6 - 将自定义字段添加到类别

标签 php prestashop prestashop-1.6

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

字段类型为TEXT

我已经覆盖了我的 Front office,并且我的字段显示得很好。

覆盖\类\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,有人可以帮忙吗?

最佳答案

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

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

  1. 更新数据库

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

  1. 覆盖类别类

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

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,代码如下:

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();
    }
}

关于php - Prestashop 1.6 - 将自定义字段添加到类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30735704/

相关文章:

php - 访问 Google_Service_Exception 中的属性时出现问题

php - 在 prestashop 中检索当前页面的不同语言的 URL

php - PrestaShop - 覆盖 Controller 不起作用

php - 在 Laravel 中使用 React Native

php - 使用一个或几个 mysql 数据库。什么适合我?

caching - Prestashop 编辑未更新

mysql - 当我尝试在 MySQL 中使用 JOIN 时收到 NULL

.htaccess - PRESTASHOP NGINX + 重写规则

command-line-interface - 清理 Prestashop 的原始产品图像以减少存储使用

php - 根据可用字体更改字体大小