Jump to content

Show Notification in admin order view page


Recommended Posts

Hello,

I am using Prestashop 1.7.7.1 and what I see here admin Order view is totally changed.
AdminOrderController is removed.

What I am trying to do is follwoing:
1. I have created a module to send a alert email to customers.
2. I have created a button "Send alert to customer" in admin using hook "actionGetAdminOrderButtons". See below image.

image.thumb.png.304b964dd3d73258a418cc4161073e2f.png

3. This button has link to same order page with additional parameter in url to identify that button is clicked.
4. When button is clicked, I get additional parameter in url and I calculate some data and send email to user.
5. Till now there is no problem.
6. The problem is I wanna display a success message if email is sent and error message if something went wrong.

image.thumb.png.40584435e34de6ff136a43428c2a784c.png

Here is my code as well

public function hookActionGetAdminOrderButtons(array $params)
{ 	 
	$id_order = $params['id_order'];
	$order = new Order((int)$id_order);
	$order_state = new OrderState((int)$order->current_state);
 
	/** @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router */
	$router = $this->get('router');
	
	/** @var \PrestaShopBundle\Controller\Admin\Sell\Order\ActionsBarButtonsCollection $bar */
	$bar = $params['actions_bar_buttons_collection'];
	$viewOrderUrl = $router->generate('admin_orders_view', ['orderId'=> $id_order]); 
	$sendPickupAlertUrl = $viewOrderUrl.'&notify=1'; 
	$bar->add(
		new \PrestaShopBundle\Controller\Admin\Sell\Order\ActionsBarButton(
			'btn-secondary', ['href' => $sendPickupAlertUrl], 'Send Alert to Customer'
		)
	); 
	
	if(Tools::getValue('notify'))
	{
		// Calculate some data
		// Send email to customer
		
		if($success)
			Show success message.
		else
			show error message.	
		 
	} 
	 
}

 

Can anyone help me how to display success or error notification message like above screenshot?

 

Thanks in advance
Peter

Link to comment
Share on other sites

  • 2 months later...

Hey. I am not a prestashop master, and I am asking the same thing.

 

There is an

 

$this->addFlash('error','text');

 

but this will fail since we are not in a controller (it should extends controller)

 

Here what I found :

Tools::displayError('Erro text');

 

 

I hope it will helps

 

 

 

Other way (I dont know if it's ok, but it works)

public function hookDisplayAdminOrderTop($params) {

$order = new Order($params['id_order']);

$router = $this->get('router');

if (....) (GET or something)

{

$message_txt="Yeah.";
$type="success"; // can be error..
$this->get('session')->getFlashBag()->add($type, $message_txt);
$urlResend = $router->generate('admin_orders_view', ['orderId'=> (int)$order->id]);

Tools::redirectAdmin($urlResend);

}

}

 

Edited by David (see edit history)
  • Thanks 3
Link to comment
Share on other sites

  • 5 months later...
On 4/14/2021 at 6:40 PM, David said:

Other way (I dont know if it's ok, but it works)

public function hookDisplayAdminOrderTop($params) {

$order = new Order($params['id_order']);

$router = $this->get('router');

if (....) (GET or something)

{

$message_txt="Yeah.";
$type="success"; // can be error..
$this->get('session')->getFlashBag()->add($type, $message_txt);
$urlResend = $router->generate('admin_orders_view', ['orderId'=> (int)$order->id]);

Tools::redirectAdmin($urlResend);

}

}

 

This worked for me.
Thanks for your help.

 

  • Like 1
Link to comment
Share on other sites

  • 5 months later...
On 4/14/2021 at 5:40 PM, David said:
$this->get('session')->getFlashBag()->add($type, $message_txt);

Hi Buddy. Thanks a lot. This one helped me in my custom module. Since i run version 1.7.7.8 and its a modern controller (not a legacy) this is working



And other methods like below are not working

Tools::displayError('Erro text');
&
$this->adminDisplayInformation($msg)

 

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...