Skip to main content
2 of 3
added 27 characters in body
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);
        if (!is_null($customerEmail) && !$emailSentStatus) {
            $shipment->sendEmail(true, $customerEmailComments);
            $shipment->setEmailSent(true);
        }

        return $this;
    }

Thanks for you time...

user1704524
  • 2.5k
  • 13
  • 60
  • 106