我的自定义模块中的覆盖前端控制器有问题。我有模块:
<?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时,如何显示通知?
我到处问,但没有人回答。
答案 0 :(得分:2)
您需要保存在yourmodule/override/controllers/front/CartController.php
中。
然后您需要像这样覆盖核心的CartController:
CartController extends CartControllerCore {
// do whatever
}
最后,您需要重置/重新安装PrestaShop模块才能自动复制覆盖。
答案 1 :(得分:1)
您可以使用命令
在控制器中显示通知$this->success[] = $this->l(' Succes info.');