Warm tip: This article is reproduced from stackoverflow.com, please click
prestashop prestashop-1.7

show js notification in front controller

发布于 2020-05-03 05:37:22

I override CartController in my custom module. But i have problem with notification, this is my code:

<?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?
            }
        }

    }

if i say problem i mean, how can i show for example js message or modal dialog when $this->qty >= 2 ?

Screen from front page, i see error i network, but i don't see notification on page enter image description here

Questioner
PawelC
Viewed
54
OnklMaps 2020-02-14 17:25

You can look into how the core cart controller shows notifications:

It should be enough to use $this->errors[] to make some error message.

            $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'
            );

Also look at FrontController other similar arrays to set notifications:

/** @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();