Skip to main content
1 of 3
user1704524
  • 2.5k
  • 13
  • 60
  • 106

Send shipping email using an Observer

I've managed to create an Observer to automatically create a shipment when an invoice is created.

The problem I have is with the final part of the code to send the email once the shipment has been created.

I wanted to ask if anyone can notice what is wrong with the $sendEmail call in my code.

Here's my Observer code for _saveShipment()

protected function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order $order, $customerEmailComments = '')
{
    $shipment->getOrder()->setIsInProcess(true);
    Mage::log($shipment->debug(),Zend_Log::INFO,'shipment.log',true);
    $transactionSave = Mage::getModel('core/resource_transaction')
        ->addObject($shipment)
        ->addObject($order)
        ->save();


    $emailSentStatus = $shipment->getData('email_sent');
    if($emailSentStatus)
        Mage::log("Email has been sent",Zend_Log::INFO,'email.log',true);
    else
        Mage::log("IS FALSE",Zend_Log::INFO,'email.log',true);
    Mage::log($customerEmailComments,Zend_Log::INFO,'email.log',true);
    if (!is_null($customerEmail) && !$emailSentStatus) {
        $shipment->sendEmail();
        $shipment->setEmailSent(true);
    }

    return true;
}

Thanks for you time...

user1704524
  • 2.5k
  • 13
  • 60
  • 106