*/ class Mage_Sales_Model_Order_Shipment_Track extends Mage_Sales_Model_Abstract { const CUSTOM_CARRIER_CODE = 'custom'; protected $_shipment = null; protected $_eventPrefix = 'sales_order_shipment_track'; protected $_eventObject = 'track'; /** * Initialize resource model */ function _construct() { $this->_init('sales/order_shipment_track'); } /** * Init mapping array of short fields to * its full names * * @resturn Varien_Object */ protected function _initOldFieldsMap() { $this->_oldFieldsMap = array( 'number' => 'track_number' ); } /** * Back compatibility with old versions. * * @return string */ public function getNumber() { return $this->getData('track_number'); } /** * Declare Shipment instance * * @param Mage_Sales_Model_Order_Shipment $shipment * @return Mage_Sales_Model_Order_Shipment_Item */ public function setShipment(Mage_Sales_Model_Order_Shipment $shipment) { $this->_shipment = $shipment; return $this; } /** * Retrieve Shipment instance * * @return Mage_Sales_Model_Order_Shipment */ public function getShipment() { if (!($this->_shipment instanceof Mage_Sales_Model_Order_Shipment)) { $this->_shipment = Mage::getModel('sales/order_shipment')->load($this->getParentId()); } return $this->_shipment; } public function isCustom() { return $this->getCarrierCode() == self::CUSTOM_CARRIER_CODE; } /** * Retrieve hash code of current order * * @return string */ public function getProtectCode() { return (string)$this->getShipment()->getProtectCode(); } /** * Retrieve detail for shipment track * * @return string */ public function getNumberDetail() { $carrierInstance = Mage::getSingleton('shipping/config')->getCarrierInstance($this->getCarrierCode()); if (!$carrierInstance) { $custom = array(); $custom['title'] = $this->getTitle(); $custom['number'] = $this->getTrackNumber(); return $custom; } else { $carrierInstance->setStore($this->getStore()); } if (!$trackingInfo = $carrierInstance->getTrackingInfo($this->getNumber())) { return Mage::helper('sales')->__('No detail for number "%s"', $this->getNumber()); } return $trackingInfo; } /** * Get store object * * @return Mage_Core_Model_Store */ public function getStore() { if ($this->getShipment()) { return $this->getShipment()->getStore(); } return Mage::app()->getStore(); } /** * Get store id * * @return int */ public function getStoreId() { return $this->getStore()->getId(); } /** * Before object save * * @return Mage_Sales_Model_Order_Shipment_Track */ protected function _beforeSave() { parent::_beforeSave(); if (!$this->getParentId() && $this->getShipment()) { $this->setParentId($this->getShipment()->getId()); } return $this; } }