I would like to send confirmation emails that are different depending on which product (not product type) is purchased. I sell a small sampling of products online - currently 5... 3 are simple, 2 are downloadable. Aside from varying different content/verbiage in the line items sections of the confirmation email, I would like to send completely different confirmation email templates if product A is bought versus product B. Different styles, different layout, etc. Has anyone done something like this before?
1 Answer
I don't have a working code for this, but here is an idea.
You can try to rewrite the Mage_Sales_Model_Order::sendNewOrderEmail()
method and use different templates depending on the products ordered.
The section in charge of determining the mail template to use is this:
if ($this->getCustomerIsGuest()) {
$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
$customerName = $this->getBillingAddress()->getName();
} else {
$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
$customerName = $this->getCustomerName();
}
You can change this in order to depend on the products.
To get the products ordered you can use in the function above:
$items = $this->getAllItems();
foreach ($items as $item) {
$itemSku = $item->getSku();
$product = $item->getProduct();
}
You can create product attribute where you can specify what template to be used then you can decide based on that. Of course you will need to specify a priority in case 2 products are ordered so you will know what template to use. But you better your logic.