00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 class Mage_Shipping_Block_Tracking_Popup extends Mage_Core_Block_Template
00028 {
00029
00030 protected $_track_id;
00031 protected $_order_id;
00032 protected $_ship_id;
00033
00034 public function setOrderId($oid)
00035 {
00036 $this->_order_id=$oid;
00037 }
00038
00039 public function getOrderId()
00040 {
00041 return $this->_order_id;
00042 }
00043
00044 public function setShipId($oid)
00045 {
00046 $this->_ship_id=$oid;
00047 }
00048
00049 public function getShipId()
00050 {
00051 return $this->_ship_id;
00052 }
00053
00054 public function setTrackId($tid='')
00055 {
00056 $this->_track_id=$tid;
00057 }
00058
00059 public function getTrackId()
00060 {
00061 return $this->_track_id;
00062 }
00063
00064
00065
00066
00067
00068
00069 protected function _initOrder()
00070 {
00071 $order = Mage::getModel('sales/order')->load($this->_order_id);
00072
00073 if (!$order->getId()) {
00074 return false;
00075 }
00076
00077 return $order;
00078 }
00079
00080
00081
00082
00083
00084
00085 protected function _initShipment()
00086 {
00087 $ship = Mage::getModel('sales/order_shipment')->load($this->_ship_id);
00088
00089 if (!$ship->getEntityId()) {
00090 return false;
00091 }
00092
00093 return $ship;
00094 }
00095
00096
00097 public function getTrackingInfo()
00098 {
00099 $this->setOrderId($this->getRequest()->getParam('order_id'));
00100 $this->setTrackId($this->getRequest()->getParam('track_id'));
00101 $this->setShipId($this->getRequest()->getParam('ship_id'));
00102
00103 if ($this->getOrderId()>0) {
00104 return $this->getTrackingInfoByOrder();
00105 } elseif($this->getShipId()>0) {
00106 return $this->getTrackingInfoByShip();
00107 } else {
00108 return $this->getTrackingInfoByTrackId();
00109 }
00110 }
00111
00112
00113
00114
00115 public function getTrackingInfoByOrder()
00116 {
00117 $shipTrack = array();
00118 if ($order = $this->_initOrder()) {
00119 $shipments = $order->getShipmentsCollection();
00120 foreach ($shipments as $shipment){
00121 $increment_id = $shipment->getIncrementId();
00122 $tracks = $shipment->getTracksCollection();
00123
00124 $trackingInfos=array();
00125 foreach ($tracks as $track){
00126 $trackingInfos[] = $track->getNumberDetail();
00127 }
00128 $shipTrack[$increment_id] = $trackingInfos;
00129 }
00130 }
00131 return $shipTrack;
00132 }
00133
00134
00135
00136
00137 public function getTrackingInfoByShip()
00138 {
00139 $shipTrack = array();
00140 if ($shipment = $this->_initShipment()) {
00141 $increment_id = $shipment->getIncrementId();
00142 $tracks = $shipment->getTracksCollection();
00143
00144 $trackingInfos=array();
00145 foreach ($tracks as $track){
00146 $trackingInfos[] = $track->getNumberDetail();
00147 }
00148 $shipTrack[$increment_id] = $trackingInfos;
00149
00150 }
00151 return $shipTrack;
00152 }
00153
00154
00155
00156
00157 public function getTrackingInfoByTrackId()
00158 {
00159 $shipTrack[] = array(Mage::getModel('sales/order_shipment_track')->load($this->getTrackId())
00160 ->getNumberDetail());
00161 return $shipTrack;
00162 }
00163
00164
00165
00166
00167 public function formatDeliveryDateTime($date,$time)
00168 {
00169 return Mage::app()->getLocale()->date(strtotime($date.' '.$time),Zend_Date::TIMESTAMP, null, false)->toString('MM/dd/YYYY hh:mm a');
00170 }
00171
00172
00173
00174
00175 public function formatDeliveryDate($date)
00176 {
00177 return Mage::app()->getLocale()->date(strtotime($date),Zend_Date::TIMESTAMP, null, false)->toString('MM/dd/YYYY');
00178 }
00179
00180
00181
00182
00183 public function formatDeliveryTime($time, $date = null)
00184 {
00185 if (!empty($date)) {
00186 $time = $date.' '.$time;
00187 }
00188 return Mage::app()->getLocale()->date(strtotime($time),Zend_Date::TIMESTAMP, null, false)->toString('hh:mm a');
00189 }
00190
00191 public function getStoreSupportEmail()
00192 {
00193 return Mage::getStoreConfig('trans_email/ident_support/email');
00194 }
00195
00196 public function getContactUs()
00197 {
00198 return $this->getUrl('contacts');
00199 }
00200
00201 }