Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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

share|improve this question
    
Have you checked whether the ifclause is actually true? –  user3154108 Aug 4 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 –  user1704524 Aug 4 at 13:57
    
Where is $customerEmail define in if (!is_null($customerEmail)..? –  R.S Aug 4 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. –  user3154108 Aug 4 at 14:19

2 Answers 2

up vote 1 down vote accepted

$customerEmail is not define try

.....
if (!is_null($shipment->getOrder()->getCustomerEmail()) && !$emailSentStatus) {
    $shipment->sendEmail(true, $customerEmailComments);
    $shipment->setEmailSent(true);
 }
share|improve this answer
    
Thankyou, that solved it $customerEmail was not defined –  user1704524 Aug 4 at 14:37

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

share|improve this answer
    
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 :( –  user1704524 Aug 4 at 14:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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