Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Strange behavior in checkout when modifying sendNewOrderEmail()
 
Jonathan Hedrén
Member
 
Total Posts:  67
Joined:  2007-08-31
Sweden
 

I’ve done a modification of Mage_Sales_Model_Order::sendNewOrderEmail() that looks like this:

public function sendNewOrderEmail()
    
{
    
        $orderData 
= array(
                     
'order'      => $this,
                     
'billing'    => $this->getBillingAddress(),
                     
'items_html' => Mage::getHelper('sales/order_email_items')->setOrder($this)->toHtml(),
                     );

        
// Send customer order mail
        
Mage::getModel('core/email_template')
            ->
sendTransactional(
              
Mage::getStoreConfig(self::XML_PATH_NEW_ORDER_EMAIL_TEMPLATE),
              
Mage::getStoreConfig(self::XML_PATH_NEW_ORDER_EMAIL_IDENTITY),
              
$this->getCustomerEmail(),
              
$this->getBillingAddress()->getName(),
              
$orderData
              
);
        
// Send storage order mail
        
Mage::getModel('core/email_template')
            ->
sendTransactional(
              
Mage::getStoreConfig('sales/mail_to_storage/email_template'),
              
Mage::getStoreConfig('sales/mail_to_storage/email_identity'),
              
Mage::getStoreConfig('sales/mail_to_storage/storage_email'),
              
'',
              
$orderData
              
);
        
        return 
$this;
    
}

The code above worked fine in version 0.6.13700 but in 0.6.14100 it doesn’t. When I run saveOrder() (i.e. press the “Place order"-button) it catches an exception and in the frontend it seems to trigger an empty javascript alert. I got even more confused when I tried this:

public function sendNewOrderEmail()
    
{
    
        Mage
::getModel('core/email_template')
            ->
sendTransactional(
              
Mage::getStoreConfig(self::XML_PATH_NEW_ORDER_EMAIL_TEMPLATE),
              
Mage::getStoreConfig(self::XML_PATH_NEW_ORDER_EMAIL_IDENTITY),
              
$this->getCustomerEmail(),
              
$this->getBillingAddress()->getName(),
              array(
            
'order'      => $this,
             
'billing'    => $this->getBillingAddress(),
             
'items_html' => Mage::getHelper('sales/order_email_items')->setOrder($this)->toHtml(),
             );
        );
    
    
//this is interesting...
    
error_log($this);
        
        return 
$this;
    
}
That doesn’t create an exception, but instead I’m not redirected to the order success page (the order is placed though). However when changing error_log($this) to for example error_log(’foo’) it works…

Also the code below “works” (i.e. I get past the last order step in the frontend and two emails are sent, one without data though):

public function sendNewOrderEmail()
    
{
    
        
// Send customer order mail
        
Mage::getModel('core/email_template')
            ->
sendTransactional(
              
Mage::getStoreConfig(self::XML_PATH_NEW_ORDER_EMAIL_TEMPLATE),
              
Mage::getStoreConfig(self::XML_PATH_NEW_ORDER_EMAIL_IDENTITY),
              
$this->getCustomerEmail(),
              
$this->getBillingAddress()->getName(),
              array(
                     
'order'      => $this,
                     
'billing'    => $this->getBillingAddress(),
                     
'items_html' => Mage::getHelper('sales/order_email_items')->setOrder($this)->toHtml(),
                     );
              );

        
// Send storage order mail              
        
Mage::getModel('core/email_template')
            ->
sendTransactional(
              
Mage::getStoreConfig('sales/mail_to_storage/email_template'),
              
Mage::getStoreConfig('sales/mail_to_storage/email_identity'),
              
Mage::getStoreConfig('sales/mail_to_storage/storage_email'),
              
''
              
);

        return 
$this;
    
}

Somehow it seems like that something goes wrong when I’m “touching” the order object ($this)…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jonathan Hedrén
Member
 
Total Posts:  67
Joined:  2007-08-31
Sweden
 

This is the exception I get:

exception 'Mage_Core_Exception' with message 'Block with name "payment.method.checkmo.383" already exists' in D:\wamp\www\magento\app\Mage.php:342
Stack trace
:
#0 D:\wamp\www\magento\app\code\core\Mage\Core\Model\Layout.php(319): Mage::throwException('Block with name...')
#1 D:\wamp\www\magento\app\code\core\Mage\Payment\Model\Checkmo.php(36): Mage_Core_Model_Layout->createBlock('payment/info', 'payment.method....')
#2 D:\wamp\www\magento\app\code\core\Mage\Sales\Model\Order\Payment.php(87): Mage_Payment_Model_Checkmo->createInfoBlock('payment.method....')
#3 D:\wamp\www\magento\lib\Varien\Filter\Template.php(174): Mage_Sales_Model_Order_Payment->getHtmlFormated()
#4 D:\wamp\www\magento\lib\Varien\Filter\Template.php(113): Varien_Filter_Template->_getVariable(' order.payment....', '')
#5 [internal function]: Varien_Filter_Template->varDirective(Array)
#6 D:\wamp\www\magento\lib\Varien\Filter\Template.php(99): call_user_func(Array, Array)
#7 D:\wamp\www\magento\app\code\core\Mage\Core\Model\Email\Template.php(153): Varien_Filter_Template->filter('<style type="te...')
#8 D:\wamp\www\magento\app\code\core\Mage\Core\Model\Email\Template.php(197): Mage_Core_Model_Email_Template->getProcessedTemplate(Array, true)
#9 D:\wamp\www\magento\app\code\core\Mage\Core\Model\Email\Template.php(231): Mage_Core_Model_Email_Template->send('jonathan.hedren...', '', Array)
#10 D:\wamp\www\magento\app\code\local\Ateles\MailToStorage\Sales\Model\Order.php(57): Mage_Core_Model_Email_Template->sendTransactional('2', 'general', 'jonathan.hedren...', '', Array)
#11 D:\wamp\www\magento\app\code\core\Mage\Checkout\Model\Type\Onepage.php(319): Ateles_MailToStorage_Sales_Model_Order->sendNewOrderEmail()
#12 D:\wamp\www\magento\app\code\core\Mage\Checkout\controllers\OnepageController.php(233): Mage_Checkout_Model_Type_Onepage->saveOrder()
#13 D:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Action.php(325): Mage_Checkout_OnepageController->saveOrderAction()
#14 D:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(149): Mage_Core_Controller_Varien_Action->dispatch('saveOrder')
#15 D:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Front.php(166): Mage_Core_Controller_Varien_Router_Standard->match(Object(Zend_Controller_Request_Http))
#16 D:\wamp\www\magento\app\Mage.php(382): Mage_Core_Controller_Varien_Front->dispatch()
#17 D:\wamp\www\magento\index.php(29): Mage::run('base')
#18 {main}

Edit:
After some research I found that it is when {{var order.payment.html_formatted}} in the mail template is called that I get the exception. I’m thinking that the easiest way to get around this problem would be to unset the “payment.method.checkmo.xxx"-block after the first mail is sent, like this:

Mage::getModel('core/layout')->unsetBlock('payment.method.'.$this->getPayment()->getMethod().'.'.$this->getPayment()->getId());
However this doesn’t work as I don’t get a layout-object… So I’m asking for some advice on this…
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top