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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
When you create a shipment, assign the tracking number dynamically using your custom module's observer. See below.
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);
}
Credit: http://ka.lpe.sh/2012/01/08/magento-save-shipment-information-tracking-number-carrier-code-programatically/