prestashop-在前端控制器中显示js通知

问题描述 投票:0回答:1

我在自定义模块中覆盖了CartController。但是我在通知方面有问题,这是我的代码:

<?php

    use PrestaShop\PrestaShop\Adapter\Presenter\Cart\CartPresenter;

    class CartController extends CartControllerCore
    {
        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?
            }
        }

    }

如果我说的是我的问题,当$ this-> qty> = 2时,如何显示js消息或模式对话框?

从首页显示的屏幕,我看到错误,网络,但是我没有在页面上看到通知enter image description here

prestashop prestashop-1.7
1个回答
0
投票

您可以查看核心购物车控制器如何显示通知:

使用$this->errors[]发出一些错误消息就足够了。

            $this->errors[] = $this->trans(
                'Add your message her with possible variables like this: %product% and %quantity%.',
                array('%product%' => $product->name, '%quantity%' => $product->minimal_quantity),
                'Shop.Notifications.Error'
            );

还请参见FrontController其他类似的数组来设置通知:

/** @var array Controller errors */
public $errors = array();

/** @var array Controller warning notifications */
public $warning = array();

/** @var array Controller success notifications */
public $success = array();

/** @var array Controller info notifications */
public $info = array();
© www.soinside.com 2019 - 2024. All rights reserved.