0

I am new to Magento and not able to figure out how to do this.

I need to add a BCC email to the order confirmation emails that are being sent when the user buys a particular product. For e.g.,

The user buys product A, the user will get an order confirmation email. This email needs to be Bcc'd for this particular product to another email id.

Could someone help me understand how to handle this. Thanks!

1

First, have a look at: Mage_Sales_Model_Order_Invoice->sendEmail() To get an idea of what Magento is doing when the mail is sent. It should be fairly apparent what you'll need to do, as the goal is to add your own BCC to that mail.

You'll also notice that $order is defined right at the top.

Now I'm assuming that you might have hundreds of products, all of which need to be BCC'ed to different people. In this case, you should be able to iterate over the order items and check a custom product attribute, say product_bcc_email, to determine if this order needs to have someone BCC'ed and which address to use, something probably looking like (not tested at all).

$items = $order->getItems();
foreach ($items as $item) {
    if ($bcc_email = $item->getProduct()->getProductBccEmail()) {
        $emailInfo = Mage::getModel('core/email_info');
        $emailInfo->addBcc($bcc_email);
        $mailer->addEmailInfo($emailInfo);
    }
}

Ultimately, you will need to determine how you want to implement this. I don't recall a good observer to place this code in, so you might have to override the Invoice model and replace the sendEmail() method with your own.

Another approach that might work (without having to override core models) would be to find an appropriate observer (maybe sales_order_place_after) and then just send an entirely separate email to the people that need to be BCC'ed. This will send two mails instead of one, but you at least get past having to override the Invoice model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.