fransjaeger Posted February 2, 2015 Share Posted February 2, 2015 Hi I miss a way to save a message before i redirect. The message should be shown to customer on the next page. Is this available in Prestashop? Thank you Link to comment Share on other sites More sharing options...
Radu Posted February 2, 2015 Share Posted February 2, 2015 You may want to check how controllers do in case of an error ($this->errors[] array) or you can implement your own way saving the data in the context/cookie 1 Link to comment Share on other sites More sharing options...
fransjaeger Posted February 2, 2015 Author Share Posted February 2, 2015 HI You mean something like this?? There isnt any pre build way to do this? Would be nice if there was a Messages class to use for this kind of messages after redirect. Link to comment Share on other sites More sharing options...
fransjaeger Posted February 2, 2015 Author Share Posted February 2, 2015 (edited) Would this fix it? $this->context->redirect_errors[] = Tools::displayError('Please log in to reorder.'); Tools::redirect(...); class FrontController extends FrontControllerCore { public function display() { // show saved messages if ($this->context->redirect_errors){ $this->errors = array_merge($this->context->redirect_errors, $this->errors); // delete old messages $this->context->redirect_errors = false; } parent::display(); } } Edited February 3, 2015 by michaelhjulskov (see edit history) Link to comment Share on other sites More sharing options...
Radu Posted February 3, 2015 Share Posted February 3, 2015 yep, I don't know of such Message class that can be used across the pages Link to comment Share on other sites More sharing options...
fransjaeger Posted February 3, 2015 Author Share Posted February 3, 2015 (edited) The above code didnt work. So im playing around with this: (which also doesnt work) $this->context->cookie->redirect_errors[] = Tools::displayError('Please log in to reorder.'); Tools::redirect(...); public function display() { // show saved messages if (isset($this->context->cookie->redirect_errors)){ $this->errors = array_merge($this->context->cookie->redirect_errors, $this->errors); // delete old messages unset($this->context->cookie->redirect_errors); } parent::display(); } Edited February 3, 2015 by michaelhjulskov (see edit history) Link to comment Share on other sites More sharing options...
fransjaeger Posted February 3, 2015 Author Share Posted February 3, 2015 (edited) ahhhh i found it! here $this->context->cookie->__set('redirect_errors', Tools::displayError('Please log in to be able to reorder.')); Tools::redirect(...); class FrontController extends FrontControllerCore { public function display() { // show saved messages if (isset($this->context->cookie->redirect_errors)){ $this->errors = array_merge($this->context->cookie->redirect_errors, $this->errors); // delete old messages unset($this->context->cookie->redirect_errors); } parent::display(); } } Hope it helps others Edited February 3, 2015 by michaelhjulskov (see edit history) 1 1 Link to comment Share on other sites More sharing options...
fransjaeger Posted February 3, 2015 Author Share Posted February 3, 2015 (edited) Here is a way to extend it even further with success message and fancybox popup public function display() { // show saved errors if (isset($this->context->cookie->redirect_errors)){ $this->errors[] = $this->context->cookie->redirect_errors; $this->context->smarty->assign(array( 'redirect_errors' => $this->context->cookie->redirect_errors, )); $this->context->cookie->__unset('redirect_errors'); } // show saved messages if (isset($this->context->cookie->redirect_success_message)){ $this->context->smarty->assign(array( 'redirect_success_message' => $this->context->cookie->redirect_success_message, )); $this->context->cookie->__unset('redirect_success_message'); } // show saved messages if (isset($this->context->cookie->redirect_fancybox_message)){ $this->context->smarty->assign(array( 'redirect_fancybox_message' => $this->context->cookie->redirect_fancybox_message, )); $this->context->cookie->__unset('redirect_fancybox_message'); } parent::display(); } errors.tpl {if isset($errors) && $errors} <div class="alert alert-danger"> <p>{if $errors|@count > 1}{l s='There are %d errors' sprintf=$errors|@count}{else}{l s='There is %d error' sprintf=$errors|@count}{/if}</p> <ol> {foreach from=$errors key=k item=error} <li>{$error}</li> {/foreach} </ol> <p class="lnk"><a href="{$smarty.server.HTTP_REFERER|escape:'html':'UTF-8'|secureReferrer}" title="{l s='Back'}">« {l s='Back'}</a></p> {/if} </div> {/if} {if isset($redirect_success_message) && $redirect_success_message} <div class="alert alert-success"> <p>{$redirect_success_message}</p> </div> {/if} {if isset($redirect_fancybox_message) && $redirect_fancybox_message} {addJsDef redirect_fancybox_message=$redirect_fancybox_message|escape:'html':'UTF-8'} {/if} and in my global.js i made this: function trigger_fancybox(msg) { if (!!$.prototype.fancybox){ $.fancybox.open([ { type: 'inline', closeClick: true, helpers : { overlay : {closeClick: true} }, autoScale: true, minHeight: 30, maxWidth: 600, content: '<p class="fancybox-error">' + msg + '</p>' } ], { padding: 0 }); } else { alert(msg); } } $(document).ready(function(){ // redirect_fancybox_message from FrontController // TODO - only show it on first load if ( (typeof redirect_fancybox_message !== "undefined" && redirect_fancybox_message) ){ trigger_fancybox(redirect_fancybox_message); } }); Edited February 3, 2015 by michaelhjulskov (see edit history) 3 Link to comment Share on other sites More sharing options...
JazZ7 Posted May 11, 2018 Share Posted May 11, 2018 (edited) Hello, For ModuleAdminController, you could use predefined success messages or add custom success messages. For error messages, use the known `$this->errors` array. In AdminController, there are predefined success messages set in the constructor. So, from your ModuleAdminController, you should be able to use them or to add custom value in the array : AdminController.php <?php //... constructor : $this->_conf = array( 1 => $this->l('Successful deletion'), 2 => $this->l('The selection has been successfully deleted.'), 3 => $this->l('Successful creation'), 4 => $this->l('Successful update'), 5 => $this->l('The status has been successfully updated.'), 6 => $this->l('The settings have been successfully updated.'), 7 => $this->l('The image was successfully deleted.'), 8 => $this->l('The module was successfully downloaded.'), 9 => $this->l('The thumbnails were successfully regenerated.'), 10 => $this->l('The message was successfully sent to the customer.'), 11 => $this->l('Comment successfully added'), 12 => $this->l('Module(s) installed successfully.'), 13 => $this->l('Module(s) uninstalled successfully.'), 14 => $this->l('The translation was successfully copied.'), 15 => $this->l('The translations have been successfully added.'), 16 => $this->l('The module transplanted successfully to the hook.'), 17 => $this->l('The module was successfully removed from the hook.'), 18 => $this->l('Successful upload'), 19 => $this->l('Duplication was completed successfully.'), 20 => $this->l('The translation was added successfully, but the language has not been created.'), 21 => $this->l('Module reset successfully.'), 22 => $this->l('Module deleted successfully.'), 23 => $this->l('Localization pack imported successfully.'), 24 => $this->l('Localization pack imported successfully.'), 25 => $this->l('The selected images have successfully been moved.'), 26 => $this->l('Your cover image selection has been saved.'), 27 => $this->l('The image\'s shop association has been modified.'), 28 => $this->l('A zone has been assigned to the selection successfully.'), 29 => $this->l('Successful upgrade'), 30 => $this->l('A partial refund was successfully created.'), 31 => $this->l('The discount was successfully generated.'), 32 => $this->l('Successfully signed in to PrestaShop Addons') ); And in your module admin controller : <?php //... constructor : parent::__construct(); // add custom success message $this->_conf[33] = $this->l('Awesome success message !'); //... redirect // use custom message $this->redirectAdmin(...'&conf=33'...); // or use predefined one $this->redirectAdmin(...'&conf=4'...); Hope it helps. Edited May 11, 2018 by JazZ7 (see edit history) 1 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