Prestashop 1.7 从模块覆盖前端控制器
Prestashop 1.7 override front controller from module
我在自定义模块中覆盖前端控制器时遇到问题。我有模块:
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class cartlimit extends Module
{
public function __construct()
{
$this->name = 'cartlimit';
$this->tab = 'front_office_features';
$this->author = 'somedata';
$this->version = '1.0.0';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('cart limit');
$this->description = $this->l('module for cart limit');
}
public function install()
{
return parent::install();
}
public function uninstall()
{
return parent::uninstall();
}
}
在我的模块中,我有控制器 override/controllers/CartController.php,代码为:
<?php
use PrestaShop\PrestaShop\Adapter\Presenter\Cart\CartPresenter;
class CartControllerCore extends FrontController
{
public $php_self = 'cart';
public function init()
{
parent::init();
$this->qty = abs(Tools::getValue('qty', 1));
var_dump(1);
if ($this->qty >= 2) {
#How can i show notification?
}
}
}
当我安装我的模块并将产品添加到购物车时,我的替代功能不起作用。 Presta 将产品添加到购物车而不是显示 var_dump。第二个问题是,当 $this->qty >= 2 时如何显示通知?
到处问,没人回答
您需要保存在yourmodule/override/controllers/front/CartController.php
。
然后你需要像这样覆盖核心 CartController:
CartController extends CartControllerCore {
// do whatever
}
最后,您需要 reset/reinstall 模块让 PrestaShop 自动复制覆盖。
您可以使用命令
在控制器中显示通知
$this->success[] = $this->l(' Succes info.');
我在自定义模块中覆盖前端控制器时遇到问题。我有模块:
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class cartlimit extends Module
{
public function __construct()
{
$this->name = 'cartlimit';
$this->tab = 'front_office_features';
$this->author = 'somedata';
$this->version = '1.0.0';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('cart limit');
$this->description = $this->l('module for cart limit');
}
public function install()
{
return parent::install();
}
public function uninstall()
{
return parent::uninstall();
}
}
在我的模块中,我有控制器 override/controllers/CartController.php,代码为:
<?php
use PrestaShop\PrestaShop\Adapter\Presenter\Cart\CartPresenter;
class CartControllerCore extends FrontController
{
public $php_self = 'cart';
public function init()
{
parent::init();
$this->qty = abs(Tools::getValue('qty', 1));
var_dump(1);
if ($this->qty >= 2) {
#How can i show notification?
}
}
}
当我安装我的模块并将产品添加到购物车时,我的替代功能不起作用。 Presta 将产品添加到购物车而不是显示 var_dump。第二个问题是,当 $this->qty >= 2 时如何显示通知?
到处问,没人回答
您需要保存在yourmodule/override/controllers/front/CartController.php
。
然后你需要像这样覆盖核心 CartController:
CartController extends CartControllerCore {
// do whatever
}
最后,您需要 reset/reinstall 模块让 PrestaShop 自动复制覆盖。
您可以使用命令
在控制器中显示通知$this->success[] = $this->l(' Succes info.');