1

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...

4
  • Have you checked whether the ifclause is actually true? Commented Aug 4, 2014 at 12:52
  • @user3154108 Hi, yes my if condition is coming back as "FALSE" I'm trying to find out why is isn't send 2014-08-04T13:52:33+00:00 INFO (6): IS FALSE Commented Aug 4, 2014 at 13:57
  • Where is $customerEmail define in if (!is_null($customerEmail)..? Commented Aug 4, 2014 at 14:15
  • Yeah, R.S is right, $customerEmail does not seem to be defined, giving an eternel null and thus a false in the if. Commented Aug 4, 2014 at 14:19

2 Answers 2

1

$customerEmail is not define try

.....
if (!is_null($shipment->getOrder()->getCustomerEmail()) && !$emailSentStatus) {
    $shipment->sendEmail(true, $customerEmailComments);
    $shipment->setEmailSent(true);
 }
1
  • Thankyou, that solved it $customerEmail was not defined Commented Aug 4, 2014 at 14:37
1

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

enter image description here

1
  • Thankyou for you response, I have made the changes and checked in admin but I am still not getting an email sent and the log still says 2014-08-04T14:21:07+00:00 INFO (6): IS FALSE :( Commented Aug 4, 2014 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.