magentoblockmagento-1.7extend

Override \app\code\core\Mage\Core\Block\Messages.php


I am trying to override the messaging block in Magento but can't get it working.

I created needed files:

\app\etc\modules\Dss_Core.xml
\app\code\local\Dss\Core\Block\Messages.php
\app\code\local\Dss\Core\etc\config.xml

I have also created a custom admin login.phtml but one is showing correctly. But when calling <?php echo $this->getMessagesBlock()->getGroupedHtml() ?> in login.phtml I don't see my message from my Dss_Core_Block_Messages.

I tried everything (changing files/clearing Magento cache) but can't get it working.

What do I need to change?

\app\etc\modules\Dss_Core.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Dss_Core>
            <active>true</active>
            <codePool>local</codePool>
        </Dss_Core>
    </modules>
</config>

\app\code\local\Dss\Core\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Dss_Core>
            <version>0.1.0</version>
        </Dss_Core>
    </modules>
    <global>
        <blocks>
           <core>
              <rewrite>
                  <messages>
                      Dss_Core_Block_Messages
                  </messages>
              </rewrite>
           </core>
        </blocks>
    </global>
</config>

\app\code\local\Dss\Core\Block\Messages.php

<?php
class DSS_Core_Block_Messages extends Mage_Core_Block_Messages
{
    public function getGroupedHtml()
    {
        return '<div class="alert alert-block" style="color: white;">custom dss errors</div>';
    }
}

\app\design\adminhtml\default\dss\template\login.phtml

<body id="page-login" onload="document.forms.loginForm.username.focus();">
    <div class="container login-container">
    <div id="messages"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
        <div class="login-box rounded">
            <form method="post" action="" id="loginForm">
                <div class="login-form">
                ...
                </div>
            </form>
        </div>
    </div>
</body>
</html>

Solution

  • Your problem is a typo in the class name DSS_Core_Block_Messages it should be Dss_Core_Block_Messages instead. You should also put your rewrite entry into one line <messages>Dss_Core_Block_Messages</messages>.