Prestashop 1.7 覆盖模块中的前端控制器

Paw*_*elC 2 prestashop prestashop-1.7

我在自定义模块中覆盖前端控制器时遇到问题。我有模块:

<?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();
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的模块中,我有控制器 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?
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

当我安装模块并将产品添加到购物车时,我的覆盖不起作用。Presta 将产品添加到购物车,而不是显示 var_dump。第二个问题是,当 $this->qty >= 2 时如何显示通知?

我到处询问,却没有人回答。

Onk*_*aps 6

您需要保存在yourmodule/override/controllers/front/CartController.php.

然后你需要像这样重写核心 CartController:

CartController extends CartControllerCore {
    // do whatever
}
Run Code Online (Sandbox Code Playgroud)

最后,您需要重置/重新安装 PrestaShop 模块以自动复制覆盖。