Magento Forum

   
[ SOLVED ] How do I get a formatted validation message that I know was added to the review/session? 
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

I’m so close on this, but I just can’t figure out how to get the message off the session. If I do this, I can see the message:

<?php

    $review_session 
Mage::getModel('review/session');
    
var_dump$review_session );

?>

Basically, I’m on the product page, trying to get a review/session message, so I need to figure out how to replace “$this” with the appropriate object. It should look something like:

<?php echo $review_session->getMessagesBlock()->getGroupedHtml() ?>

I tried to set $review_session as getSingleton and getModel for various objects, but none of them seem to have a getMessagesBlock() method available.

Can someone help me figure this out? Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

$messages Mage::getSingleton('review/session')->getMessages();
/magento/app/code/core/Mage/Core/Model/Message/Collection.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

Hi Lee,

Thanks for the response. Sorry, I should have been more clear in my post. I can get the messages, but I need to get it formatted, just like this:

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>

If you look at getGroupedHtml(), you can see how it formats the messaging nicely. I need to take the message I have, which we know is appearing in review/session, and figure out how to get from that to getMessagesBlock()->getGroupedHtml().

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

Can anyone help out with this? I know the message exists, and has been added to the session, and I can get it as text. However, I want it as it is pulled from the block, formatted, just like when you use:

$this->getMessagesBlock()->getGroupedHtml()

I’ve managed to figure out that the class that “gets” the message is Mage_Review_Block_List_Detailed. I just can’t figure out how Magento associates a block with a message on the session. Mage_Core_Block_Abstract is the class that owns the method getMessagesBlock(), and Mage_Review_Block_List_Detailed extends that class. However, how do I call this class in such a way that I can call getMessagesBlock()?

The reason I need to do this is because I moved all product reviews and the form onto the product details page. Everything works fine, I can page reviews, and even submit a review. However, when I submit a review I get no confirmation message. That is because the confirmation message is associated with Mage_Review_Block_List_Detailed, and not Mage_Catalog_Block_Product_View (the product page).

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

I don’t know if this is the best solution, but it is the solution that worked for me based upon what I’ve dissected in the core. I took the messages I knew could be added to the review/session and I added them to the messages block for the current object before calling getGroupedHtml(). It looks like this:

<?php

$this
->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('review/session')->getMessages(true));
echo 
$this->getMessagesBlock()->getGroupedHtml();
    
?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
miked2004
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2007-12-13
Atlanta, Georgia
 

@ hal - Thanks for posting your solution. I found my self in a similar predicament. I created a custom module and could not get the messages showing up. using your hack worked for me. although I would like to figure out why

echo $this->getMessagesBlock()->getGroupedHtml()
did not work. Must not have set something up incorrectly.

 
Magento Community Magento Community
Magento Community
Magento Community
 
quanza
Sr. Member
 
Avatar
Total Posts:  97
Joined:  2008-12-02
Tokyo, Japan
 

How would I get just the array of messages as text?  I don’t like how it’s styled, and would like an opportunity to filter the text before it’s displayed in a template ...

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikola99
Member
 
Total Posts:  47
Joined:  2010-04-09
 

You can rewrite app/code/core/Mage/Core/Block/Messages.php to change the HTML in the messages, however, you’d probably be best off using CSS.

In case someone else stumbles upon this. I had to turn the cart into a request a quote. in order for this to work I had to change the confirmation message when an item is added to the cart ("Something was successfully added to your shopping cart/quote.")

I changed app/design/frontend/nti/default/template/checkout/cart.phtml

I replaced this

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>

with this

<?php echo str_replace('shopping cart'strtolower($title), $this->getMessagesBlock()->getGroupedHtml()) ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
sachu777
Jr. Member
 
Total Posts:  2
Joined:  2010-10-31
 

Thanks a million @HAL10001 that code worked for me .......

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ricardo_Martins
Member
 
Avatar
Total Posts:  47
Joined:  2009-02-04
Santos, SP, Brazil
 
HAL10001 - 08 October 2008 04:40 PM

I don’t know if this is the best solution, but it is the solution that worked for me based upon what I’ve dissected in the core. I took the messages I knew could be added to the review/session and I added them to the messages block for the current object before calling getGroupedHtml(). It looks like this:

<?php

$this
->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('review/session')->getMessages(true));
echo 
$this->getMessagesBlock()->getGroupedHtml();
    
?>

It worked very well for me either in the customer/session blocks.
Thank you very much.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top