如何覆盖 prestashop 1.6 中的构造函数和 public 变量
How to override constructor function and public variable in prestashop 1.6
我有一个覆盖产品 class 的自定义模块。这是我的代码:
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');
}
}
当我安装模块时,没有错误。但是在覆盖文件夹中,product.php 文件我没有看到
public $variable;
需要自己添加。问题出在哪里?
感谢您的帮助。
-编辑
这是下面答案的代码输出。如您所见,没有 public $变量。为什么?
/*
* 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 声明(在自己的行中打开和关闭大括号),它将正确解析覆盖。
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');
}
}
已解决。要解决这个问题,您需要首先放置构造函数。最后,添加变量声明。如下所示。
class 产品扩展 ProductCore
{
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;
}
我有一个覆盖产品 class 的自定义模块。这是我的代码:
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');
}
}
当我安装模块时,没有错误。但是在覆盖文件夹中,product.php 文件我没有看到
public $variable;
需要自己添加。问题出在哪里?
感谢您的帮助。
-编辑 这是下面答案的代码输出。如您所见,没有 public $变量。为什么?
/*
* 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 声明(在自己的行中打开和关闭大括号),它将正确解析覆盖。
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');
}
}
已解决。要解决这个问题,您需要首先放置构造函数。最后,添加变量声明。如下所示。
class 产品扩展 ProductCore {
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;
}