PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Sales/doc/test.php

https://gitlab.com/LisovyiEvhenii/ismextensions
PHP | 305 lines | 157 code | 32 blank | 116 comment | 37 complexity | 4d7ea87f963d0256869405e6a1d19b0b MD5 | raw file
  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@magento.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.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Sales
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. include "lib/Varien/Object.php";
  27. class Test {
  28. protected $_order;
  29. public function runTest()
  30. {
  31. $this->_order = new Varien_Object;
  32. #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>";
  33. echo "<table border=1><tr><td>Order</td><td>Payment</td><td>Refund</td><td>Shipping</td><td>Actions</td></tr>";
  34. foreach (array('new', 'onhold', 'processing', 'complete', 'closed', 'cancelled', 'void') as $orderStatus) {
  35. $this->getOrder()->setOrderStatus($orderStatus);
  36. foreach (array('not_authorized', 'pending', 'authorized', 'partial', 'paid') as $paymentStatus) {
  37. $this->getOrder()->setPaymentStatus($paymentStatus);
  38. foreach (array('pending', 'partial', 'shipped') as $shippingStatus) {
  39. $this->getOrder()->setShippingStatus($shippingStatus);
  40. foreach (array('not_refunded', 'partial', 'refunded') as $refundStatus) {
  41. $this->getOrder()->setRefundStatus($refundStatus);
  42. // foreach (array('not_returned', 'partial', 'returned') as $returnStatus) {
  43. // $this->getOrder()->setReturnStatus($returnStatus);
  44. if (!$this->validateOrderStatus()) {
  45. continue;
  46. }
  47. $adminStatus = $this->getAdminStatus();
  48. $frontendStatus = $this->getFrontendStatus();
  49. $actions = $this->getOrderActions();
  50. $actions = join(', ', array_keys($actions));
  51. #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>";
  52. echo "<tr><td>$orderStatus</td><td>$paymentStatus</td><td>$refundStatus</td><td>$shippingStatus</td><td>$actions</td></tr>";
  53. // }
  54. }
  55. }
  56. }
  57. }
  58. echo "</table>";
  59. }
  60. public function getOrder()
  61. {
  62. return $this->_order;
  63. }
  64. /**
  65. * Check if type and status matches for the order
  66. *
  67. * @param string $type order, payment, shipment
  68. * @param string $status comma separated
  69. * - order
  70. * - new
  71. * - onhold
  72. * - processing
  73. * - complete
  74. * - closed
  75. * - cancelled
  76. * - void
  77. *
  78. * - payment
  79. * - not_authorized
  80. * - pending
  81. * - authorized
  82. * - partial
  83. * - paid
  84. *
  85. * - shipping
  86. * - pending
  87. * - partial
  88. * - shipped
  89. *
  90. * - refund
  91. * - not_refunded
  92. * - pending
  93. * - partial
  94. * - refunded
  95. *
  96. * - return
  97. * - not_returned
  98. * - partial
  99. * - returned
  100. */
  101. function matchOrderStatus($type, $status) {
  102. $statuses = explode(',', $status);
  103. $value = $this->getOrder()->getData($type.'_status');
  104. foreach ($statuses as $status) {
  105. if ($value==$status) {
  106. return true;
  107. }
  108. }
  109. return false;
  110. }
  111. function validateOrderStatus()
  112. {
  113. if ($this->matchOrderStatus('order', 'new')) {
  114. if (!$this->matchOrderStatus('shipping', 'pending')
  115. // || !$this->matchOrderStatus('return', 'not_returned')
  116. || !$this->matchOrderStatus('refund', 'not_refunded')
  117. ) {
  118. return false;
  119. }
  120. if ($this->matchOrderStatus('payment', 'partial')) {
  121. return false;
  122. }
  123. }
  124. if ($this->matchOrderStatus('order', 'onhold')) {
  125. if (!$this->matchOrderStatus('shipping', 'pending')
  126. || !$this->matchOrderStatus('payment', 'pending')
  127. || !$this->matchOrderStatus('refund', 'not_refunded')
  128. // || !$this->matchOrderStatus('return', 'not_returned')
  129. ) {
  130. return false;
  131. }
  132. }
  133. if ($this->matchOrderStatus('order', 'cancelled')) {
  134. if (!$this->matchOrderStatus('shipping', 'pending')
  135. || !$this->matchOrderStatus('payment', 'pending,not_authorized')
  136. || !$this->matchOrderStatus('refund', 'not_refunded')
  137. // || !$this->matchOrderStatus('return', 'not_returned')
  138. ) {
  139. return false;
  140. }
  141. }
  142. if ($this->matchOrderStatus('order', 'complete,closed')) {
  143. if (!$this->matchOrderStatus('payment', 'paid')
  144. || !$this->matchOrderStatus('shipping', 'shipped')
  145. ) {
  146. return false;
  147. }
  148. }
  149. if ($this->matchOrderStatus('order', 'void')) {
  150. if ($this->matchOrderStatus('payment', 'pending,not_authorized')) {
  151. return false;
  152. }
  153. if (!$this->matchOrderStatus('refund', 'not_refunded')) {
  154. return false;
  155. }
  156. }
  157. if ($this->matchOrderStatus('payment', 'pending,not_authorized')
  158. && !$this->matchOrderStatus('refund', 'not_refunded')
  159. ) {
  160. return false;
  161. }
  162. if ($this->matchOrderStatus('payment', 'authorized')
  163. && !$this->matchOrderStatus('refund', 'not_refunded')
  164. ) {
  165. return false;
  166. }
  167. if ($this->matchOrderStatus('payment', 'partial')
  168. && $this->matchOrderStatus('refund', 'refunded')
  169. ) {
  170. return false;
  171. }
  172. // if ($this->matchOrderStatus('shipping', 'pending')
  173. // && !$this->matchOrderStatus('return', 'not_returned')
  174. // ) {
  175. // return false;
  176. // }
  177. //
  178. // if ($this->matchOrderStatus('shipping', 'partial') && $this->matchOrderStatus('return', 'returned')) {
  179. // return false;
  180. // }
  181. return true;
  182. }
  183. /**
  184. * Available actions for admin user
  185. *
  186. * @return array available actions array
  187. * - cancel
  188. * - authorize
  189. * - capture
  190. * - invoice
  191. * - creditmemo
  192. * - hold
  193. * - unhold
  194. * - ship
  195. * - edit
  196. * - comment
  197. * - status
  198. * - reorder
  199. */
  200. function getOrderActions()
  201. {
  202. $actions = array();
  203. $actions['comment'] = 1;
  204. if ($this->matchOrderStatus('order', 'cancelled')) {
  205. $actions['reorder'] = 1;
  206. return $actions;
  207. }
  208. if ($this->matchOrderStatus('order', 'closed')) {
  209. $actions['reorder'] = 1;
  210. if (!$this->matchOrderStatus('refund', 'refunded')) {
  211. $actions['creditmemo'] = 1;
  212. }
  213. return $actions;
  214. }
  215. if ($this->matchOrderStatus('order', 'onhold')) {
  216. $actions['unhold'] = 1;
  217. return $actions;
  218. }
  219. $actions['edit'] = 1;
  220. $actions['hold'] = 1;
  221. if (!$this->matchOrderStatus('order', 'void')) {
  222. $actions['cancel'] = 1;
  223. }
  224. if ($this->matchOrderStatus('payment', 'not_authorized')) {
  225. $actions['authorize'] = 1;
  226. $actions['capture'] = 1;
  227. }
  228. if (!$this->matchOrderStatus('payment', 'not_authorized,pending,paid')) {
  229. $actions['invoice'] = 1;
  230. }
  231. if (!$this->matchOrderStatus('shipping', 'shipped')) {
  232. $actions['ship'] = 1;
  233. }
  234. if ($this->matchOrderStatus('payment', 'partial,paid') && !$this->matchOrderStatus('refund', 'refunded')) {
  235. $actions['creditmemo'] = 1;
  236. }
  237. if ($this->matchOrderStatus('order', 'void')) {
  238. unset($actions['ship'], $actions['invoice'], $actions['ship'], $actions['hold']);
  239. }
  240. return $actions;
  241. }
  242. /**
  243. * Order status for admin
  244. *
  245. * @return array
  246. * - new
  247. * - pending
  248. * - processing
  249. * - complete
  250. * - cancelled
  251. */
  252. function getAdminStatus()
  253. {
  254. return $this->getOrder()->getOrderStatus();
  255. }
  256. /**
  257. * Order status for customers
  258. *
  259. * @return array
  260. * - new
  261. * - pending
  262. * - processing
  263. * - complete
  264. * - cancelled
  265. */
  266. function getFrontendStatus()
  267. {
  268. return $this->getOrder()->getOrderStatus();
  269. }
  270. }
  271. $test = new Test;
  272. $test->runTest();