1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: include "lib/Varien/Object.php";
27:
28: class Test {
29: protected $_order;
30:
31: public function runTest()
32: {
33: $this->_order = new Varien_Object;
34:
35: echo "<table border=1><tr><td>Order</td><td>Payment</td><td>Refund</td><td>Shipping</td><td>Actions</td></tr>";
36: foreach (array('new', 'onhold', 'processing', 'complete', 'closed', 'cancelled', 'void') as $orderStatus) {
37: $this->getOrder()->setOrderStatus($orderStatus);
38: foreach (array('not_authorized', 'pending', 'authorized', 'partial', 'paid') as $paymentStatus) {
39: $this->getOrder()->setPaymentStatus($paymentStatus);
40: foreach (array('pending', 'partial', 'shipped') as $shippingStatus) {
41: $this->getOrder()->setShippingStatus($shippingStatus);
42: foreach (array('not_refunded', 'partial', 'refunded') as $refundStatus) {
43: $this->getOrder()->setRefundStatus($refundStatus);
44:
45:
46: if (!$this->validateOrderStatus()) {
47: continue;
48: }
49: $adminStatus = $this->getAdminStatus();
50: $frontendStatus = $this->getFrontendStatus();
51: $actions = $this->getOrderActions();
52: $actions = join(', ', array_keys($actions));
53:
54: echo "<tr><td>$orderStatus</td><td>$paymentStatus</td><td>$refundStatus</td><td>$shippingStatus</td><td>$actions</td></tr>";
55:
56: }
57: }
58: }
59: }
60: echo "</table>";
61: }
62:
63: public function getOrder()
64: {
65: return $this->_order;
66: }
67:
68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105:
106: function matchOrderStatus($type, $status) {
107: $statuses = explode(',', $status);
108: $value = $this->getOrder()->getData($type.'_status');
109: foreach ($statuses as $status) {
110: if ($value==$status) {
111: return true;
112: }
113: }
114: return false;
115: }
116:
117: function validateOrderStatus()
118: {
119: if ($this->matchOrderStatus('order', 'new')) {
120: if (!$this->matchOrderStatus('shipping', 'pending')
121:
122: || !$this->matchOrderStatus('refund', 'not_refunded')
123: ) {
124: return false;
125: }
126: if ($this->matchOrderStatus('payment', 'partial')) {
127: return false;
128: }
129: }
130:
131: if ($this->matchOrderStatus('order', 'onhold')) {
132: if (!$this->matchOrderStatus('shipping', 'pending')
133: || !$this->matchOrderStatus('payment', 'pending')
134: || !$this->matchOrderStatus('refund', 'not_refunded')
135:
136: ) {
137: return false;
138: }
139: }
140:
141: if ($this->matchOrderStatus('order', 'cancelled')) {
142: if (!$this->matchOrderStatus('shipping', 'pending')
143: || !$this->matchOrderStatus('payment', 'pending,not_authorized')
144: || !$this->matchOrderStatus('refund', 'not_refunded')
145:
146: ) {
147: return false;
148: }
149: }
150:
151: if ($this->matchOrderStatus('order', 'complete,closed')) {
152: if (!$this->matchOrderStatus('payment', 'paid')
153: || !$this->matchOrderStatus('shipping', 'shipped')
154: ) {
155: return false;
156: }
157: }
158:
159: if ($this->matchOrderStatus('order', 'void')) {
160: if ($this->matchOrderStatus('payment', 'pending,not_authorized')) {
161: return false;
162: }
163: if (!$this->matchOrderStatus('refund', 'not_refunded')) {
164: return false;
165: }
166: }
167:
168: if ($this->matchOrderStatus('payment', 'pending,not_authorized')
169: && !$this->matchOrderStatus('refund', 'not_refunded')
170: ) {
171: return false;
172: }
173:
174: if ($this->matchOrderStatus('payment', 'authorized')
175: && !$this->matchOrderStatus('refund', 'not_refunded')
176: ) {
177: return false;
178: }
179:
180: if ($this->matchOrderStatus('payment', 'partial')
181: && $this->matchOrderStatus('refund', 'refunded')
182: ) {
183: return false;
184: }
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196: return true;
197: }
198:
199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215:
216: function getOrderActions()
217: {
218: $actions = array();
219:
220: $actions['comment'] = 1;
221:
222: if ($this->matchOrderStatus('order', 'cancelled')) {
223: $actions['reorder'] = 1;
224: return $actions;
225: }
226:
227: if ($this->matchOrderStatus('order', 'closed')) {
228: $actions['reorder'] = 1;
229: if (!$this->matchOrderStatus('refund', 'refunded')) {
230: $actions['creditmemo'] = 1;
231: }
232: return $actions;
233: }
234:
235: if ($this->matchOrderStatus('order', 'onhold')) {
236: $actions['unhold'] = 1;
237: return $actions;
238: }
239:
240: $actions['edit'] = 1;
241:
242: $actions['hold'] = 1;
243:
244: if (!$this->matchOrderStatus('order', 'void')) {
245: $actions['cancel'] = 1;
246: }
247:
248: if ($this->matchOrderStatus('payment', 'not_authorized')) {
249: $actions['authorize'] = 1;
250: $actions['capture'] = 1;
251: }
252:
253: if (!$this->matchOrderStatus('payment', 'not_authorized,pending,paid')) {
254: $actions['invoice'] = 1;
255: }
256:
257:
258: if (!$this->matchOrderStatus('shipping', 'shipped')) {
259: $actions['ship'] = 1;
260: }
261:
262: if ($this->matchOrderStatus('payment', 'partial,paid') && !$this->matchOrderStatus('refund', 'refunded')) {
263: $actions['creditmemo'] = 1;
264: }
265:
266: if ($this->matchOrderStatus('order', 'void')) {
267: unset($actions['ship'], $actions['invoice'], $actions['ship'], $actions['hold']);
268: }
269:
270: return $actions;
271: }
272:
273: 274: 275: 276: 277: 278: 279: 280: 281: 282:
283: function getAdminStatus()
284: {
285: return $this->getOrder()->getOrderStatus();
286: }
287:
288: 289: 290: 291: 292: 293: 294: 295: 296: 297:
298: function getFrontendStatus()
299: {
300: return $this->getOrder()->getOrderStatus();
301: }
302: }
303:
304: $test = new Test;
305: $test->runTest();
306: