Question

I am updating a Magento 1 payment module which was maintained years ago.

The module does this in the ProcessingController.php for each action:

public function redirectAction(){
    // processing code

    // end of function
    $this->loadLayout();
    $this->getLayout()->getBlock('root')->setTemplate('page/1column.phtml');
    $this->getLayout()->getBlock('content')->append($this->getLayout()->createBlock('pay/processing'));
    $this->renderLayout();
}

Each of the blocks (for example pay/processing used above) do not use layout or template files.

Everything is done inside each Block's _toHtml() function:

protected function _toHtml(){
    echo "<div><span>Content here is static text mostly</span></div>";
}

Now, I have created a new block using the same way the method is setup, pay/returnaction:

public function redirectAction() {

      // code to determine if logged in or not

     // render on error
     if ($not_loggedin){
            $this->loadLayout();
            $this->getLayout()->getBlock('root')->setTemplate('page/1column.phtml');
                $blockReturn = $this->getLayout()->createBlock('pay/returnaction');
                $blockReturn->setHasError_NotLoggedIn();
            $this->getLayout()->getBlock('content')->append($blockReturn);
            $this->renderLayout();
     }
     else{
        // render other static block
    }
}

class Cre8aweb_Pay_Block_Returnaction extends Mage_Core_Block_Abstract{

 private $_helper = 'pay/Data';

protected function _toHtml(){
      $script = "<p>Start Content</p>";
      $script .= $this->getNotLoggedInError();
      $script .= "<p>Exra Content</p>";
      $script .= "<script>";
      $script .= "setTimeout(function() { location.href='/customer/account/login'}, 6000);";
      $script .= "</script>";

      return $script;
  }

        protected function getNotLoggedInError(){
                $errorText = '';
                if($this->_hasError_NotLoggedIn){
                        $errorText = $this->_getHelper()->notLoggedInError();
                }
                return $errorText;
        }

        private function _getHelper(){
                return Mage::helper($this->_helper);
        }

}

So basically, I want to call $block->getNotLoggedInError() which returns text content from the helper.

At the moment when the block is shown is only - the getNotLoggedInError() most likely just returns empty string when _toHtml() gets called.

How do I correctly create the new block in the controller, send data it depends on from the controller and make sure that all block content is shown.

Current result:

Start Content
End Content

Expected result:

Start Content
Not logged in notification - 
End Content

Keep in mind this is when returned from the payment processor sometimes the customer session is lost somehow. So instead of throwing an exception which currently happens (sporadically!!), I would rather want to notify the customer that the information is not available, and they should login again.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top