Program mail sending / tracking

In Magento 1.4, I successfully use this code to mark an order as completed and add a delivery 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 works correctly, but I can’t find the right piece of code that I need to send a confirmation email to the client, for example, when you check the correct frame and check the delivery in the magento blender.

Thank you for your help.

+5
source share
2 answers
                if($shipment){
                    if(!$shipment->getEmailSent()){
                        $shipment->sendEmail(true);
                        $shipment->setEmailSent(true);
                        $shipment->save();                          
                    }
                }   
+5
source

... , sales/order_shipment_track , Api, , Api sendInfo() . ( $ship OP $shipmentApi)

    //add tracking info ($shippingCarrier is case sensitive)
    $shipmentApi->addTrack($shipmentIncrementId, $shippingCarrier, $shippingTitle, $trackingNumber);

    //send shipment email with tracking info
    $shipmentApi->sendInfo($shipmentIncrementId);

:

if($order->canShip()){

    $shipmentApi = Mage::getModel('sales/order_shipment_api');

    //pass false for email, unless you want Magento to send the shipment email without any tracking info
    //could also be written as $shipmentIncrementId = $shipmentApi->create($order->getIncrementId());
    $shipmentIncrementId = $shipmentApi->create($order->getIncrementId(), array(), '' , false, 0); 

    //add tracking info ($shippingCarrier is case sensitive)
    $shipmentApi->addTrack($shipmentIncrementId, $shippingCarrier, $shippingTitle, $trackingNumber);

    //send shipment email with tracking info
    $shipmentApi->sendInfo($shipmentIncrementId);
}

. app\code\core\Mage\Sales\Model\Order\Shipment\Api.php .

0

All Articles