Prestashop 如何在模块重写类中重写定义?

Prestashop 如何在模块重写类中重写定义?,prestashop,prestashop-1.5,Prestashop,Prestashop 1.5,下面的答案将是这样的代码: Product::$definition['fields']['mystock'] = array('type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedInt'); class Product extends ProductCore { public $mystock; } 但它不起作用 p、 我想添加一个定义规则 upd 1. 这是我在模块中对供

下面的答案将是这样的代码:

Product::$definition['fields']['mystock'] = array('type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedInt');
    class Product extends ProductCore 
    { 
       public $mystock; 
    }
但它不起作用

p、 我想添加一个定义规则

upd 1.

这是我在模块中对
供应商
类的工作覆盖:

class Supplier extends SupplierCore
{
    /** @var string Email */
    public $email;

    /**
     * @see ObjectModel::$definition
     */
    public static $definition = array(
            'table' => 'supplier',
            'primary' => 'id_supplier',
            'multilang' => true,
            'fields' => array(
                    'name' =>                                 array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
                    'active' =>                         array('type' => self::TYPE_BOOL),
                    'date_add' =>                         array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
                    'date_upd' =>                         array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
                    'email' =>                         array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128),

                    // Lang fields
                    'description' =>                 array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
                    '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),
            ),
    );

    public function __construct($id = null, $id_lang = null)
    {   
        parent::__construct($id, $id_lang);
    }
}
upd 2.

这是错误的一面:

Supplier::$definition['fields']['email'] = array('type' => ObjectModel::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128);

class Supplier extends SupplierCore
{
    /** @var string Email */
    public $email;

    public function __construct($id = null, $id_lang = null)
    {   
        parent::__construct($id, $id_lang);
    }
}
如果可能的话,如何做到这一点

upd 3.最好在提交表单的某个地方添加它,然后再检查:

$validation = $address->validateController();

            // checks address validity
            if (count($validation) > 0)
            {
                foreach ($validation as $item)
                    $this->errors[] = $item;
                $this->errors[] = Tools::displayError('The address is not correct. Please make sure all of the required fields are completed.');
            }

但是怎么做呢?

我认为你把定义放错地方了。 在供应商的覆盖类中尝试以下代码:

class Supplier extends SupplierCore
{
    /** @var string Email */
    public $email;

    public function __construct($id = null, $id_lang = null)
    {   
        self::$definition['fields']['email'] = array('type' => ObjectModel::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128);
        parent::__construct($id, $id_lang);
    }
}