Jump to content

How to show custom notifications or error message at admin panel for prestashop 1.7.7.7?


Recommended Posts

Hi, 

I've been trying a lot of options to manage an exception and show an error at admin panel but nothing seems to work.

I'm at the postProcess method of a custom module. After the user sends a csv file through a form and the data is checked (everything works fine here), if an exception occurs I need to show a message, stop and redirect to the same page. 

I've tried this: 

this->get('session')->getFlashBag()->add('error',$msg);
Tools::redirectAdmin('index.php?controller='.$controller.'&token='.$token);

this: 

header("HTTP/1.0 400 Bad Request");
die(json_encode(array( 'error' => array($this->l(' Error') ))));

(that one works but shows a blank page with the message, not the message inside the admin panel) 

also this: 

$this->context->smarty->assign(array(
	'token' => Tools::getAdminTokenLite('AdminModules'),
	'errors' => $this->errors
));
$this->setTemplate('ExcelProcess.tpl');

and {$errors|var_dump} at the tpl displays null...

... and many other options. 

I can't find anything either about backoffice custom notifications at the PS docs, only about front custom notifications.

Any clue? 

 

Thanks a lot! 

Miguel

postProcess.txt ExcelProcess.tpl

Link to comment
Share on other sites

Are you doing this in an admin controller, or in the module configuration page?

If you do this in an admin controller, you don't have to set a specific template, you just need only to add the error in the errorrs array:

$this->errors[] = 'Your error';

and call parent::postProcess ();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...