0

I would like to automatically add the last 4 digits of invoices, when it exists, to be a tracking number for every order. How do I do that? Thanks

4

1 回答 1

2

创建货件时,使用自定义模块的观察者动态分配跟踪号。见下文。

配置文件

<sales_order_shipment_save_before>
    <observers>
        <namespace_modulename_ship_before>
            <type>singleton</type>
            <class>Namespace_Modulename_Model_Observer</class>
            <method>salesOrderShipmentSaveBefore</method>
        </namespace_modulename_ship_before>
    </observers>
</sales_order_shipment_save_before>

观察者.php

public function salesOrderShipmentSaveBefore($observer)
{
    $invoice = $observer->getEvent()->getInvoice();
    $last4 = substr($invoice->getIncrementId(), -4);

    $shipment = $observer->getEvent()->getShipment();
    $track = Mage::getModel('sales/order_shipment_track')
                ->setNumber($last4) //tracking number / awb number
                ->setCarrierCode('custom') //carrier code
                ->setTitle('Custom'); //carrier title
    $shipment->addTrack($track);
}

信用: http: //ka.lpe.sh/2012/01/08/magento-save-shipment-information-tracking-number-carrier-code-programatically/

于 2013-04-29T11:30:41.247 回答