我在自定义模块中覆盖了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消息或模式对话框?
您可以查看核心购物车控制器如何显示通知:
使用$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();