If a user tries to login with wrong credentials then normally a message appears which says "login failed", it works if I do it on the normal login form at /customer/account/login/
But if I am at a product and attempt to login with wrong credentials then the site just reloads but no error messages shows. But if I then go to the site /customer/account/login/
then I see that the error message is rendered there.
If I attempt to login two times with wrong credentials in the product page and then go back to /customer/account/login/
, then the message is getting rendered two times.
I looked up the code from the login page to find out which codeline is needed to show the error messages and found this code:
<?php echo $this->getMessagesBlock()->toHtml() ?>
so I added it to the product view, but it is still not rendering.
I also added this code:
<?php
$debugObject = Mage::getSingleton('customer/session')->getMessages();
echo "Last added message: '" . $debugObject->getLastAddedMessage() . "' <br><br>";
echo "getErrors: " . var_dump($debugObject->getErrors()) . " <br><br>";
Now I get this output:
Last added message: ''
array(1) { [0]=> object(Mage_Core_Model_Message_Error)#137 (6) { ["_type":protected]=> string(5) "error" ["_code":protected]=> string(39) "Ungültiger Benutzername oder Passwort." ["_class":protected]=> string(0) "" ["_method":protected]=> string(0) "" ["_identifier":protected]=> NULL ["_isSticky":protected]=> bool(false) } } getErrors:
But I still don't know how I can show the message in a regular way.
I was only able to hack it into the view (app\design\frontend\venedor\custom\template\catalog\product\view.phtml) like this, but I don't think that this is the way to go:
<?php $session = Mage::getSingleton('customer/session'); ?>
<?php if ($session->getMessages()->toString()) { ?>
<div class="messages">
<div class="alert alert-danger error-msg">
<button type="button" class="close" data-dismiss="alert">×</button>
<ul>
<li><?php echo str_replace ('error: ', '', $session->getMessages()->toString()) ?></li>
</ul>
</div>
</div>
<?php $session->getMessages()->clear(); ?>
<?php } ?>
There must be a cleaner solution. Why is <?php echo $this->getMessagesBlock()->toHtml() ?>
not working on the product view?