I would like to add a new block in the customer registration, edit and billing forms. This block will contain a dropdown control where the customer can select if he wants to register as a company or as an individual.
At first, I edited billing.phtml and added the following:
<li class="fields">
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('mynamespace/mymodule/customer/widget/registeras.phtml')->toHtml(); ?>
</li>
This is working fine, but instead of using 'core/template', I would like to create my custom typed block.
I wrote this in the config:
<config>
<modules>
<Mynamespace_Mymodule>
<version>0.0.1</version>
</Mynamespace_Mymodule>
</modules>
<global>
<blocks>
<mymodule>
<class>Mynamespace_Mymodule_Block_Widget_Registeras</class>
</mymodule>
</blocks>
...
</global>
</config>
Then I created the class of my block:
class Mynamespace_Mymodule_Block_Widget_Registeras extends Mage_Customer_Block_Widget_Abstract
{
public function _construct()
{
parent::_construct();
// default template location
$this->setTemplate('mynamespace/mymodule/customer/widget/registeras.phtml');
}
/**
* Get current customer from session
*
* @return Mage_Customer_Model_Customer
*/
public function getCustomer()
{
return Mage::getSingleton('customer/session')->getCustomer();
}
}
Now I replaced:
$this->getLayout()->createBlock('core/template')->setTemplate('mynamespace/mymodule/customer/widget/registeras.phtml')->toHtml(); ?>
by this:
<?php echo $this->getLayout()->createBlock('mynamespace_mymodule/widget_registeras')->setObject($this->getQuote()->getCustomer())->toHtml(); ?>
But it's not working. Here is the error I get:
exception 'Mage_Core_Exception' with message 'Invalid block type: Mage_Mynamespace_Mymodule_Block_Widget_Registeras' in E:\myworkspace\magento\app\Mage.php:595 Stack trace: 0 E:\myworkspace\magento\app\code\core\Mage\Core\Model\Layout.php(495): Mage::throwException('Invalid block t...') 1 E:\myworkspace\magento\app\code\core\Mage\Core\Model\Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('mynamespace_my...', Array) 2 E:\myworkspace\magento\app\code\core\Mage\Core\Model\Layout.php(472): Mage_Core_Model_Layout->createBlock('mynamespace_my...', 'widget_register...') ...
I could not understand why magento adds 'Mage_' to the class name.
I also tried to load it using the layout and getChildHtml() but I could not get it work better.
Any help would be appreciated.
Thank you