温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - Prestashop 1.7 override front controller from module
prestashop prestashop-1.7

其他 - Prestashop 1.7从模块覆盖前置控制器

发布于 2020-05-03 04:03:08

我的自定义模块中的覆盖前端控制器有问题。我有模块:

<?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();
    }
}

在我的模块中,我有代码的controlleroverride / 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时,如何显示通知?

我到处问,但没有人回答。

查看更多

提问者
PawelC
被浏览
10
OnklMaps 2020-02-13 22:48

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

然后,您需要像这样覆盖核心的CartController:

CartController extends CartControllerCore {
    // do whatever
}

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