PeterDesouza Posted February 4, 2021 Share Posted February 4, 2021 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. 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. 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.'¬ify=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 More sharing options...
PeterDesouza Posted February 6, 2021 Author Share Posted February 6, 2021 Hi, Any Prestashop Master who can help me... Please. Thanks Link to comment Share on other sites More sharing options...
PeterDesouza Posted February 8, 2021 Author Share Posted February 8, 2021 Anyone..? Link to comment Share on other sites More sharing options...
David Posted April 14, 2021 Share Posted April 14, 2021 (edited) 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 April 14, 2021 by David (see edit history) 3 Link to comment Share on other sites More sharing options...
PeterDesouza Posted September 26, 2021 Author Share Posted September 26, 2021 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. 1 Link to comment Share on other sites More sharing options...
Ali Samie Posted March 10, 2022 Share Posted March 10, 2022 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now