Send shipping email using an Observer
-
11-12-2019 - |
Question
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->setEmailSent(true);
$shipment->sendEmail(true, $customerEmailComments);
}
return $this;
}
Thanks for you time...
Solution
$customerEmail
is not define try
.....
if (!is_null($shipment->getOrder()->getCustomerEmail()) && !$emailSentStatus) {
$shipment->sendEmail(true, $customerEmailComments);
$shipment->setEmailSent(true);
}
OTHER TIPS
Just change the position
$shipment->sendEmail(true, $customerEmailComments);
$shipment->setEmailSent(true);
to
$shipment->setEmailSent(true);
$shipment->sendEmail(true, $customerEmailComments);
Also sales Shipment email sendEmail()
depends on condition:Mage::helper('sales')->canSendNewShipmentEmail($storeId)
Check Shipment setting is enable from admin
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange