我想自动将发票的最后4位数字(如果存在)添加为每个订单的跟踪编号。我怎么做?感谢
答案 0 :(得分:2)
创建货件时,使用自定义模块的观察者动态分配跟踪编号。见下文。
config.xml中
<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>
Observer.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);
}