00001 <?php
00002
00003 include "lib/Varien/Object.php";
00004
00005 class Test {
00006 protected $_order;
00007
00008 public function runTest()
00009 {
00010 $this->_order = new Varien_Object;
00011 #echo "<table border=1><tr><td>Order</td><td>Payment</td><td>Shipping</td><td>Refund</td><td>Return</td><td>Admin Status</td><td>Frontend Status</td><td>Actions</td></tr>";
00012 echo "<table border=1><tr><td>Order</td><td>Payment</td><td>Refund</td><td>Shipping</td><td>Actions</td></tr>";
00013 foreach (array('new', 'onhold', 'processing', 'complete', 'closed', 'cancelled', 'void') as $orderStatus) {
00014 $this->getOrder()->setOrderStatus($orderStatus);
00015 foreach (array('not_authorized', 'pending', 'authorized', 'partial', 'paid') as $paymentStatus) {
00016 $this->getOrder()->setPaymentStatus($paymentStatus);
00017 foreach (array('pending', 'partial', 'shipped') as $shippingStatus) {
00018 $this->getOrder()->setShippingStatus($shippingStatus);
00019 foreach (array('not_refunded', 'partial', 'refunded') as $refundStatus) {
00020 $this->getOrder()->setRefundStatus($refundStatus);
00021
00022
00023 if (!$this->validateOrderStatus()) {
00024 continue;
00025 }
00026 $adminStatus = $this->getAdminStatus();
00027 $frontendStatus = $this->getFrontendStatus();
00028 $actions = $this->getOrderActions();
00029 $actions = join(', ', array_keys($actions));
00030 #echo "<tr><td>$orderStatus</td><td>$paymentStatus</td><td>$shippingStatus</td><td>$refundStatus</td><td>$returnStatus</td><td>$adminStatus</td><td>$frontendStatus</td><td>$actions</td></tr>";
00031 echo "<tr><td>$orderStatus</td><td>$paymentStatus</td><td>$refundStatus</td><td>$shippingStatus</td><td>$actions</td></tr>";
00032
00033 }
00034 }
00035 }
00036 }
00037 echo "</table>";
00038 }
00039
00040 public function getOrder()
00041 {
00042 return $this->_order;
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 function matchOrderStatus($type, $status) {
00084 $statuses = explode(',', $status);
00085 $value = $this->getOrder()->getData($type.'_status');
00086 foreach ($statuses as $status) {
00087 if ($value==$status) {
00088 return true;
00089 }
00090 }
00091 return false;
00092 }
00093
00094 function validateOrderStatus()
00095 {
00096 if ($this->matchOrderStatus('order', 'new')) {
00097 if (!$this->matchOrderStatus('shipping', 'pending')
00098
00099 || !$this->matchOrderStatus('refund', 'not_refunded')
00100 ) {
00101 return false;
00102 }
00103 if ($this->matchOrderStatus('payment', 'partial')) {
00104 return false;
00105 }
00106 }
00107
00108 if ($this->matchOrderStatus('order', 'onhold')) {
00109 if (!$this->matchOrderStatus('shipping', 'pending')
00110 || !$this->matchOrderStatus('payment', 'pending')
00111 || !$this->matchOrderStatus('refund', 'not_refunded')
00112
00113 ) {
00114 return false;
00115 }
00116 }
00117
00118 if ($this->matchOrderStatus('order', 'cancelled')) {
00119 if (!$this->matchOrderStatus('shipping', 'pending')
00120 || !$this->matchOrderStatus('payment', 'pending,not_authorized')
00121 || !$this->matchOrderStatus('refund', 'not_refunded')
00122
00123 ) {
00124 return false;
00125 }
00126 }
00127
00128 if ($this->matchOrderStatus('order', 'complete,closed')) {
00129 if (!$this->matchOrderStatus('payment', 'paid')
00130 || !$this->matchOrderStatus('shipping', 'shipped')
00131 ) {
00132 return false;
00133 }
00134 }
00135
00136 if ($this->matchOrderStatus('order', 'void')) {
00137 if ($this->matchOrderStatus('payment', 'pending,not_authorized')) {
00138 return false;
00139 }
00140 if (!$this->matchOrderStatus('refund', 'not_refunded')) {
00141 return false;
00142 }
00143 }
00144
00145 if ($this->matchOrderStatus('payment', 'pending,not_authorized')
00146 && !$this->matchOrderStatus('refund', 'not_refunded')
00147 ) {
00148 return false;
00149 }
00150
00151 if ($this->matchOrderStatus('payment', 'authorized')
00152 && !$this->matchOrderStatus('refund', 'not_refunded')
00153 ) {
00154 return false;
00155 }
00156
00157 if ($this->matchOrderStatus('payment', 'partial')
00158 && $this->matchOrderStatus('refund', 'refunded')
00159 ) {
00160 return false;
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 return true;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 function getOrderActions()
00194 {
00195 $actions = array();
00196
00197 $actions['comment'] = 1;
00198
00199 if ($this->matchOrderStatus('order', 'cancelled')) {
00200 $actions['reorder'] = 1;
00201 return $actions;
00202 }
00203
00204 if ($this->matchOrderStatus('order', 'closed')) {
00205 $actions['reorder'] = 1;
00206 if (!$this->matchOrderStatus('refund', 'refunded')) {
00207 $actions['creditmemo'] = 1;
00208 }
00209 return $actions;
00210 }
00211
00212 if ($this->matchOrderStatus('order', 'onhold')) {
00213 $actions['unhold'] = 1;
00214 return $actions;
00215 }
00216
00217 $actions['edit'] = 1;
00218
00219 $actions['hold'] = 1;
00220
00221 if (!$this->matchOrderStatus('order', 'void')) {
00222 $actions['cancel'] = 1;
00223 }
00224
00225 if ($this->matchOrderStatus('payment', 'not_authorized')) {
00226 $actions['authorize'] = 1;
00227 $actions['capture'] = 1;
00228 }
00229
00230 if (!$this->matchOrderStatus('payment', 'not_authorized,pending,paid')) {
00231 $actions['invoice'] = 1;
00232 }
00233
00234
00235 if (!$this->matchOrderStatus('shipping', 'shipped')) {
00236 $actions['ship'] = 1;
00237 }
00238
00239 if ($this->matchOrderStatus('payment', 'partial,paid') && !$this->matchOrderStatus('refund', 'refunded')) {
00240 $actions['creditmemo'] = 1;
00241 }
00242
00243 if ($this->matchOrderStatus('order', 'void')) {
00244 unset($actions['ship'], $actions['invoice'], $actions['ship'], $actions['hold']);
00245 }
00246
00247 return $actions;
00248 }
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 function getAdminStatus()
00261 {
00262 return $this->getOrder()->getOrderStatus();
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 function getFrontendStatus()
00276 {
00277 return $this->getOrder()->getOrderStatus();
00278 }
00279 }
00280
00281 $test = new Test;
00282 $test->runTest();