1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Shipping
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Sales orders controller
29: *
30: * @category Mage
31: * @package Mage_Sales
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Shipping_TrackingController extends Mage_Core_Controller_Front_Action
36: {
37: /**
38: * Ajax action
39: *
40: */
41: public function ajaxAction()
42: {
43: if ($order = $this->_initOrder()) {
44: $response = '';
45: $tracks = $order->getTracksCollection();
46:
47: $className = Mage::getConfig()->getBlockClassName('core/template');
48: $block = new $className();
49: $block->setType('core/template')
50: ->setIsAnonymous(true)
51: ->setTemplate('sales/order/trackinginfo.phtml');
52:
53: foreach ($tracks as $track){
54: $trackingInfo = $track->getNumberDetail();
55: $block->setTrackingInfo($trackingInfo);
56: $response .= $block->toHtml()."\n<br />";
57: }
58:
59: $this->getResponse()->setBody($response);
60: }
61: }
62:
63: /**
64: * Popup action
65: * Shows tracking info if it's present, otherwise redirects to 404
66: */
67: public function popupAction()
68: {
69: $shippingInfoModel = Mage::getModel('shipping/info')->loadByHash($this->getRequest()->getParam('hash'));
70: Mage::register('current_shipping_info', $shippingInfoModel);
71: if (count($shippingInfoModel->getTrackingInfo()) == 0) {
72: $this->norouteAction();
73: return;
74: }
75: $this->loadLayout();
76: $this->renderLayout();
77: }
78:
79:
80: /**
81: * Initialize order model instance
82: *
83: * @return Mage_Sales_Model_Order || false
84: */
85: protected function _initOrder()
86: {
87: $id = $this->getRequest()->getParam('order_id');
88:
89: $order = Mage::getModel('sales/order')->load($id);
90: $customerId = Mage::getSingleton('customer/session')->getCustomerId();
91:
92: if (!$order->getId() || !$customerId || $order->getCustomerId() != $customerId) {
93: return false;
94: }
95: return $order;
96: }
97:
98: }
99: