Well, your sendmailbasedonsku function doesn’t set the email body text anywhere. Compare:
public function sendMail($message) {
$body = "$message";
$emailTemplate = Mage::getModel('core/email');
$emailTemplate->setFromName('GIRI Test mail');
$emailTemplate->setBody($body);
$emailTemplate->setSubject("Custom Email from observer");
$emailTemplate->setType('html');
and
public function sendMailbasedOnSku($sku)
{
Mage::log('Line no: 94 '. $sku,null,'test_sku.log',true);
$chk_sku=(int)substr($sku, 0, 1);
$emailTemplate = Mage::getModel('core/email');
That’s coming from sendMail(), even though you have all the checks to see which email to send it to, your email message body there comes from $finalMessage, which starts with <p>, so all your sku checks drop through to your else. I don’t understand why you look at the sku when you’re sending the final message, because it contains all the skus on the order.
Now 95% working exactly, if order placed with two products with sku combination like 2 & 3, Now mail received by exact both mail - abc@gmail.com (sku start with - 2) & xyz@gmail.com (sku start with - 3) but empty message, and also as you know last mail id in if condition received with data,
@aveevan: please either use example.com for your example email addresses, or enclose them in backticks ` to prevent the forum software automatically creating mailto links.
As I said before, your sendmailbasedonsku() function doesn’t set the message body. Compare the start of the sendmail function to see how it differs in its handling of $emailTemplate.
As I said earlier, that’s because you send $finalMessage using the sendmail() function, and in that function you’re still setting the destination address by looking at $sku, except that you don’t pass $sku into the function. Hence (presumably) it hits the else, though I’d just expect error messages unless the way you call the code is suppressing them somehow.
But you still have a problem - if you have two items in the order that start with the same digit, you’ll get a separate email for each of them, rather than getting them both on the same email.
Everything I said in the last post is still wrong. You still don’t set the email message body or other settings in the ...bysku() function, and you still have conditional destination addresses in the summary email function that I don’t think you need to have. You now send the final message twice, for some reason.
Where do you do that? This is your function code:
public function sendMailbasedOnSku($sku)
{
// Mage::log('Line no: 94 '. $sku,null,'test_sku.log',true);
$chk_sku=(int)substr($sku, 0, 1);
$emailTemplate = Mage::getModel('core/email');
… followed by your if…then section to set the to-address. I don’t see where you specify the message body.
Or, to put it another way, how does it work now? That is, does it do what you want it to? If it does, there’s nothing further to do.
Just the same way that you do it in sendMail() presumably - you have these lines at the top of that function:
public function sendMail($message) {
$body = "$message";
$emailTemplate = Mage::getModel('core/email');
$emailTemplate->setFromName('GIRI Test mail');
$emailTemplate->setBody($body);
$emailTemplate->setSubject("Custom Email from observer");
$emailTemplate->setType('html');
so presumably you have to have all of those in sendmailbasedonsku() as well.
You’ve changed the code now so that it doesn’t actually send the email for each item on the order based on the sku, now it only sends the mail at the end. By the time it gets there, the value of $sku is whatever it was at the end of the loop, so that’s how the decision is made on where to send it. You were closer with the previous code, in that it would at least send separate messages.