0

My observer :

<?php
    class Gta_MerchantNotification_Model_Observer
    {
        public function merchantremainder($Observer)
        {
            $order = $Observer->getEvent()->getOrder();
            $order_details = $order->getAllVisibleItems();
            foreach ($order_details as $list) {
                $incrementid = $order->getIncrementId();
                $sku = $list->getsku();
                $name = $list->getName();
                $price = $list->getPrice();
                $Qty = $list->getQtyOrdered();


                Mage::log("Id : $incrementid, Sku : $sku, Product name : $name, Price : $price, Qty Ordered : $Qty",  null, 'merchant.log', true);

            }
        }
}

?>

Output ;

Id : 100000083, Sku : #14, Product name : The Step F1004 Step Workout System, Price : 28.5, Qty Ordered : 1

How to send mail?

3

You can try below code.

<?php
class Gta_MerchantNotification_Model_Observer
{
    public function merchantremainder($Observer)
    {
        $order = $Observer->getEvent()->getOrder();
        $order_details = $order->getAllVisibleItems();
        foreach ($order_details as $list) {
            $incrementid = $order->getIncrementId();
            $sku = $list->getsku();
            $name = $list->getName();
            $price = $list->getPrice();
            $Qty = $list->getQtyOrdered();

            $message = "Id : ". $incrementid . "Sku : ". $sku . "Product name : ". $name . "Price : " . $price . "Qty Ordered : ". $Qty;
            $this->sendMail($message);
            Mage::log("Id : $incrementid, Sku : $sku, Product name : $name, Price : $price, Qty Ordered : $Qty",  null, 'merchant.log', true);
        }
    }

    public function sendMail($message) 
    {
        $body = "<p>".$message."</p>";
        $mail = Mage::getModel('core/email');
        $mail->setToName('Your Name');
        $mail->setToEmail('Youe Email');
        $mail->setBody($body);
        $mail->setSubject('Mail Subject');
        $mail->setFromEmail('Sender Mail Id');
        $mail->setFromName("Msg to Show on Subject");
        $mail->setType('html');// You can use Html or text as Mail format

        try {
            $mail->send();
            Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
        }
        catch (Exception $e) {
            Mage::getSingleton('core/session')->addError('Unable to send.');
        }
    }
}

?>
|improve this answer|||||
1

You can use the below code to send an email.

$body = "Your Response";
$emailTemplate = Mage::getModel('core/email');
$emailTemplate->setFromName('Your Store Name');
$emailTemplate->setBody($body);
$emailTemplate->setSubject("Custom Email from observer");
$emailTemplate->setType('html');
$emailTemplate->setToEmail('testing@example.com');
$emailTemplate->send();
|improve this answer|||||

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.