如何在prestashop 1.6中重写构造函数和公共变量

如何在prestashop 1.6中重写构造函数和公共变量,prestashop,Prestashop,我有一个重写产品类的自定义模块。这是我的代码: class Product extends ProductCore { public $variable; public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { parent::__construct($id_product

我有一个重写产品类的自定义模块。这是我的代码:

class Product extends ProductCore {
    public $variable;

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) {
        parent::__construct($id_product, $full, $id_lang, $id_shop);

        self::$definition['fields']['variable'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool');
    }

}
当我安装模块时,没有错误。但在override文件夹中,我看不到product.php文件

public $variable;
我需要自己加上去。问题在哪里

谢谢你的帮助

-编辑 这是下面答案中代码的输出。就像yuo-see一样,没有公共$variable。为什么?

/*
* module: mymodule
* date: 2018-06-06 15:08:01
* version: 1.0.0
*/
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) {
    parent::__construct($id_product, $full, $id_lang, $id_shop);
    self::$definition['fields']['variable'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool');
}

使用Prestashop的类声明编码标准(在自己的行中打开和关闭大括号),它将正确解析重写

class Product extends ProductCore
{
    public $variable;

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) 
    {
        parent::__construct($id_product, $full, $id_lang, $id_shop);

        self::$definition['fields']['variable'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool');
    }
}

解决了。要解决这个问题,首先需要将构造函数放在首位。最后,添加变量的声明。如下图所示

类产品扩展了ProductCore {


}

再次检查我的问题我添加了新结果。虽然这可能有效,但我记得我在卸载具有类似覆盖的模块时遇到了问题。解析器只会切断方法声明行,剩下的部分会在整个过程中导致致命错误。当我像在我的回答中那样格式化覆盖时,一切正常。尽管有可能他们在最新的1.6版本中修复了它。
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {        
        parent::__construct($id_product, $full, $id_lang, $id_shop);
        self::$definition['fields']['variable'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool');        
    }

public $variable;