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_Sales
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 MAbout This Orderage_Sales
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Sales_GuestController extends Mage_Sales_Controller_Abstract
36: {
37: /**
38: * Try to load valid order and register it
39: *
40: * @param int $orderId
41: * @return bool
42: */
43: protected function _loadValidOrder($orderId = null)
44: {
45: return Mage::helper('sales/guest')->loadValidOrder();
46: }
47:
48: /**
49: * Check order view availability
50: *
51: * @param Mage_Sales_Model_Order $order
52: * @return bool
53: */
54: protected function _canViewOrder($order)
55: {
56: $currentOrder = Mage::registry('current_order');
57: if ($order->getId() && ($order->getId() === $currentOrder->getId())) {
58: return true;
59: }
60: return false;
61: }
62:
63: protected function _viewAction()
64: {
65: if (!$this->_loadValidOrder()) {
66: return;
67: }
68:
69: $this->loadLayout();
70: Mage::helper('sales/guest')->getBreadcrumbs($this);
71: $this->renderLayout();
72: }
73:
74: /**
75: * Order view form page
76: */
77: public function formAction()
78: {
79: if (Mage::getSingleton('customer/session')->isLoggedIn()) {
80: $this->_redirect('customer/account/');
81: return;
82: }
83: $this->loadLayout();
84: Mage::helper('sales/guest')->getBreadcrumbs($this);
85: $this->renderLayout();
86: }
87:
88: public function printInvoiceAction()
89: {
90: if (!$this->_loadValidOrder()) {
91: return;
92: }
93:
94: $invoiceId = (int) $this->getRequest()->getParam('invoice_id');
95: if ($invoiceId) {
96: $invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
97: $order = $invoice->getOrder();
98: } else {
99: $order = Mage::registry('current_order');
100: }
101:
102: if ($this->_canViewOrder($order)) {
103: if (isset($invoice)) {
104: Mage::register('current_invoice', $invoice);
105: }
106: $this->loadLayout('print');
107: $this->renderLayout();
108: } else {
109: $this->_redirect('sales/guest/form');
110: }
111: }
112:
113: public function printShipmentAction()
114: {
115: if (!$this->_loadValidOrder()) {
116: return;
117: }
118:
119: $shipmentId = (int) $this->getRequest()->getParam('shipment_id');
120: if ($shipmentId) {
121: $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
122: $order = $shipment->getOrder();
123: } else {
124: $order = Mage::registry('current_order');
125: }
126: if ($this->_canViewOrder($order)) {
127: if (isset($shipment)) {
128: Mage::register('current_shipment', $shipment);
129: }
130: $this->loadLayout('print');
131: $this->renderLayout();
132: } else {
133: $this->_redirect('sales/guest/form');
134: }
135: }
136:
137: public function printCreditmemoAction()
138: {
139: if (!$this->_loadValidOrder()) {
140: return;
141: }
142:
143: $creditmemoId = (int) $this->getRequest()->getParam('creditmemo_id');
144: if ($creditmemoId) {
145: $creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemoId);
146: $order = $creditmemo->getOrder();
147: } else {
148: $order = Mage::registry('current_order');
149: }
150:
151: if ($this->_canViewOrder($order)) {
152: if (isset($creditmemo)) {
153: Mage::register('current_creditmemo', $creditmemo);
154: }
155: $this->loadLayout('print');
156: $this->renderLayout();
157: } else {
158: $this->_redirect('sales/guest/form');
159: }
160: }
161: }
162: