Programmatically send shipping/tracking mail

前端 未结 2 552
忘掉有多难
忘掉有多难 2021-02-04 19:43

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\')-         


        
2条回答
  •  后悔当初
    2021-02-04 20:19

    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.

提交回复
热议问题