Programmatically send shipping/tracking mail

早过忘川 提交于 2019-12-03 00:40:17
                if($shipment){
                    if(!$shipment->getEmailSent()){
                        $shipment->sendEmail(true);
                        $shipment->setEmailSent(true);
                        $shipment->save();                          
                    }
                }   

I spent alot of time messing with this myself...instead of using the sales/order_shipment_track model to add tracking, you can use the same Api you used to create the shipment, and then follow that with the Api's sendInfo() method to send the shipment email with tracking info. (renamed $ship from OP's example to $shipmentApi)

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

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

Full example:

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);
}

See app\code\core\Mage\Sales\Model\Order\Shipment\Api.php for all methods.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!