Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically send shipping/tracking mail

In Magento 1.4, I am successfully using this code to mark an order as Complete and add a shipping tracking code to it :

$order = Mage::getModel('sales/order')->loadByIncrementId($increment_id);

if($order->canShip())
{
$itemQty =  $order->getItemsCollection()->count();
$ship = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty);
$ship = new Mage_Sales_Model_Order_Shipment_Api();
$shipmentId = $ship->create($increment_id);
}

$shipment_collection = Mage::getResourceModel('sales/order_shipment_collection');
$shipment_collection->addAttributeToFilter('order_id', $order_id);

foreach($shipment_collection as $sc) {
    $shipment = Mage::getModel('sales/order_shipment');
    $shipment->load($sc->getId());
    if($shipment->getId() != '') { 
        $track = Mage::getModel('sales/order_shipment_track')
                 ->setShipment($shipment)
                 ->setData('title', $type)
                 ->setData('number', $code)
                 ->setData('carrier_code', 'custom')
                 ->setData('order_id', $shipment->getData('order_id'))
                 ->save();
        }
} 

It is working properly, but I cannot find the right piece of code I need to send shipment confirmation mail to customer, as when you check the right box and validate shipping in magento backend.

Thank you a lot in advance for your help.

like image 789
Roatha Chann Avatar asked Mar 27 '12 09:03

Roatha Chann


1 Answers

                if($shipment){
                    if(!$shipment->getEmailSent()){
                        $shipment->sendEmail(true);
                        $shipment->setEmailSent(true);
                        $shipment->save();                          
                    }
                }   
like image 52
magento2new Avatar answered Oct 02 '22 09:10

magento2new