When I submit review form its properly redirect back on same page and review is properly saved in admin but there is no success message.
How do I show the success message on that page and where I can set that message ?
magento2messagesreview
When I submit review form its properly redirect back on same page and review is properly saved in admin but there is no success message.
How do I show the success message on that page and where I can set that message ?
Try to give your div-container a css-class:
<div id="messages_product_view" class="test1"><?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?> <?php echo Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml(); ?> </div>
And then you define this class in your css-file:
.test1 {z-index: 99999;}
I'm not shure if it works, but on our website it is solved so.
For ajax calls you need to return the error messages if any. It does not work with $session->addError()
. The message you set with addError
are picked up on the next page load.
You need to do something like this in your controller:
public function doSomeAjaxStuff()
{
$response = array();
$response['success'] = true;
//do stuff here
$response['something'] = 'Something';
if (some error occurs) {
$response['success'] = false;
$response['message'] = 'Your error message here';
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response);
}
And in your javascript code that handles the response from the ajax call do this:
if (!response.success) {
alert(response.message);
//or insert response.message somewhere in the dom
}
Best Answer
Take a look:
vendor/magento/module-review/Controller/Product/Post.php
When we want to set this message, we have two options:
+We can use translation.
+We can override this class.
Note: the global message may store in local storage