温馨提示:本文翻译自stackoverflow.com,查看原文请点击:prestashop - show js notification in front controller
prestashop prestashop-1.7

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

发布于 2020-05-03 14:54:32

我在自定义模块中覆盖了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消息或模式对话框?

从首页上的屏幕,我看到错误我的网络,但是我在页面上没有看到通知 在此处输入图片说明

查看更多

提问者
PawelC
被浏览
12
OnklMaps 2020-02-14 17:25

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

它足以用来$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();