Magento – New order email code

emailsalessales-order

I am having a bit of trouble finding the code in Magento which relates to sending the new order email to the admin emails specified in the Configuration > Sales menu in the back-end.

Where is this coding please?

I would like to put in an if statement saying

if the order has items with attribute => value 
       then send to 1st email address;
 else
       send to 2nd email address`

What file should i be looking for to override and place this code into?

Thanks

Best Answer

You can find sendNewOrderEmail this method in Mage_Sales_Model_Order class. sendNewOrderEmail method responsible to send new order. that is.. this code should be under "$mailer" object.

$items = $this->getAllItems(); // get all products from order
    foreach ($items as $item){
        $product =    Mage::getModel('catalog/product')->loadByAttribute('sku',$item->getSku());
        if($product->getId()) {
            $emailInfo = Mage::getModel('core/email_info');

            if('if the order has items with attribute => value' ) {
                $emailInfo->addTo($email);
                $mailer->addEmailInfo($emailInfo);
            } else {
                $emailInfo->addTo($email);
                $mailer->addEmailInfo($emailInfo);
            }
        }
    }

Don't forget to rewrite this method before change logic.

Related Topic