I'm, trying to define and implement observers to catch comments on the checkout page and write them into the database. But when I want to place an order I get the following exception:
Mage registry key "_singleton/checkoutcomments/observer" already exists
Do I get this error because the model is not called properly?
Here is my code:
The config.xml
of the module
<frontend>
<layout>
<updates>
<checkoutcomments>
<file>practice/checkoutcomments.xml</file>
</checkoutcomments>
</updates>
</layout>
<events>
<controller_action_predispatch_checkout_onepage_saveOrder>
<observers>
<save_checkout_comments>
<class>checkoutcomments/observer</class>
<method>prepareCheckoutComment</method>
</save_checkout_comments>
</observers>
</controller_action_predispatch_checkout_onepage_saveOrder>
<sales_order_place_after>
<observers>
<save_checkout_comments>
<class>checkoutcomments/observer</class>
<method>saveCheckoutComment</method>
</save_checkout_comments>
</observers>
</sales_order_place_after>
</events>
</frontend>
My Observer.php
<?php
class Practice_CheckoutComments_Model_Observer
{
public function prepareCheckoutComment ($observer)
{
$message = $observer->getControllerAction()
->getRequest()
->getPost('checkoutcomments');
Mage::getSingleton('core/session')->setCheckoutComment($message);
}
public function saveCheckoutComment ($observer)
{
$order = $observer->getOrder();
$message = Mage::getSingleton('core/session')->getCheckoutComment(true);
if (!$order || empty($message)) {
return;
}
$commentModel = Mage::getModel('checkoutcomments/comment');
$commentModel->setOrderId($order->getId())
->setComment($message)
->save();
}
}
?>
<global>
section of yourconfig.xml
?