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:
27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 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: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310:
311: class Mage_Sales_Model_Order extends Mage_Sales_Model_Abstract
312: {
313: const ENTITY = 'order';
314: 315: 316:
317: const XML_PATH_EMAIL_TEMPLATE = 'sales_email/order/template';
318: const XML_PATH_EMAIL_GUEST_TEMPLATE = 'sales_email/order/guest_template';
319: const XML_PATH_EMAIL_IDENTITY = 'sales_email/order/identity';
320: const XML_PATH_EMAIL_COPY_TO = 'sales_email/order/copy_to';
321: const XML_PATH_EMAIL_COPY_METHOD = 'sales_email/order/copy_method';
322: const XML_PATH_EMAIL_ENABLED = 'sales_email/order/enabled';
323:
324: const XML_PATH_UPDATE_EMAIL_TEMPLATE = 'sales_email/order_comment/template';
325: const XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE = 'sales_email/order_comment/guest_template';
326: const XML_PATH_UPDATE_EMAIL_IDENTITY = 'sales_email/order_comment/identity';
327: const XML_PATH_UPDATE_EMAIL_COPY_TO = 'sales_email/order_comment/copy_to';
328: const XML_PATH_UPDATE_EMAIL_COPY_METHOD = 'sales_email/order_comment/copy_method';
329: const XML_PATH_UPDATE_EMAIL_ENABLED = 'sales_email/order_comment/enabled';
330:
331: 332: 333:
334: const STATE_NEW = 'new';
335: const STATE_PENDING_PAYMENT = 'pending_payment';
336: const STATE_PROCESSING = 'processing';
337: const STATE_COMPLETE = 'complete';
338: const STATE_CLOSED = 'closed';
339: const STATE_CANCELED = 'canceled';
340: const STATE_HOLDED = 'holded';
341: const STATE_PAYMENT_REVIEW = 'payment_review';
342:
343: 344: 345:
346: const STATUS_FRAUD = 'fraud';
347:
348: 349: 350:
351: const ACTION_FLAG_CANCEL = 'cancel';
352: const ACTION_FLAG_HOLD = 'hold';
353: const ACTION_FLAG_UNHOLD = 'unhold';
354: const ACTION_FLAG_EDIT = 'edit';
355: const ACTION_FLAG_CREDITMEMO= 'creditmemo';
356: const ACTION_FLAG_INVOICE = 'invoice';
357: const ACTION_FLAG_REORDER = 'reorder';
358: const ACTION_FLAG_SHIP = 'ship';
359: const = 'comment';
360:
361: 362: 363:
364: const REPORT_DATE_TYPE_CREATED = 'created';
365: const REPORT_DATE_TYPE_UPDATED = 'updated';
366: 367: 368:
369: const HISTORY_ENTITY_NAME = 'order';
370:
371: protected $_eventPrefix = 'sales_order';
372: protected $_eventObject = 'order';
373:
374: protected $_addresses = null;
375: protected $_items = null;
376: protected $_payments = null;
377: protected $_statusHistory = null;
378: protected $_invoices;
379: protected $_tracks;
380: protected $_shipments;
381: protected $_creditmemos;
382:
383: protected $_relatedObjects = array();
384: protected $_orderCurrency = null;
385: protected $_baseCurrency = null;
386:
387: 388: 389: 390: 391:
392: protected $_actionFlag = array();
393:
394: 395: 396: 397: 398:
399: protected $_canSendNewEmailFlag = true;
400:
401: 402: 403: 404: 405:
406: protected $_historyEntityName = self::HISTORY_ENTITY_NAME;
407:
408: 409: 410:
411: protected function _construct()
412: {
413: $this->_init('sales/order');
414: }
415:
416: 417: 418: 419: 420: 421:
422: protected function _initOldFieldsMap()
423: {
424: $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order');
425: return $this;
426: }
427:
428: 429: 430: 431: 432: 433:
434: public function unsetData($key=null)
435: {
436: parent::unsetData($key);
437: if (is_null($key)) {
438: $this->_items = null;
439: }
440: return $this;
441: }
442:
443: 444: 445: 446: 447: 448:
449: public function getActionFlag($action)
450: {
451: if (isset($this->_actionFlag[$action])) {
452: return $this->_actionFlag[$action];
453: }
454: return null;
455: }
456:
457: 458: 459: 460: 461: 462: 463:
464: public function setActionFlag($action, $flag)
465: {
466: $this->_actionFlag[$action] = (boolean) $flag;
467: return $this;
468: }
469:
470: 471: 472: 473: 474:
475: public function getCanSendNewEmailFlag()
476: {
477: return $this->_canSendNewEmailFlag;
478: }
479:
480: 481: 482: 483: 484: 485:
486: public function setCanSendNewEmailFlag($flag)
487: {
488: $this->_canSendNewEmailFlag = (boolean) $flag;
489: return $this;
490: }
491:
492: 493: 494: 495: 496: 497:
498: public function loadByIncrementId($incrementId)
499: {
500: return $this->loadByAttribute('increment_id', $incrementId);
501: }
502:
503: 504: 505: 506: 507: 508: 509:
510: public function loadByAttribute($attribute, $value)
511: {
512: $this->load($value, $attribute);
513: return $this;
514: }
515:
516: 517: 518: 519: 520:
521: public function getStore()
522: {
523: $storeId = $this->getStoreId();
524: if ($storeId) {
525: return Mage::app()->getStore($storeId);
526: }
527: return Mage::app()->getStore();
528: }
529:
530: 531: 532: 533: 534:
535: public function canCancel()
536: {
537: if ($this->canUnhold()) {
538: return false;
539: }
540:
541: $allInvoiced = true;
542: foreach ($this->getAllItems() as $item) {
543: if ($item->getQtyToInvoice()) {
544: $allInvoiced = false;
545: break;
546: }
547: }
548: if ($allInvoiced) {
549: return false;
550: }
551:
552: $state = $this->getState();
553: if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
554: return false;
555: }
556:
557: if ($this->getActionFlag(self::ACTION_FLAG_CANCEL) === false) {
558: return false;
559: }
560:
561: 562: 563:
564: 565: 566: 567: 568: 569:
570: return true;
571: }
572:
573: 574: 575: 576:
577: public function canVoidPayment()
578: {
579: if ($this->canUnhold() || $this->isPaymentReview()) {
580: return false;
581: }
582: $state = $this->getState();
583: if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
584: return false;
585: }
586: return $this->getPayment()->canVoid(new Varien_Object);
587: }
588:
589: 590: 591: 592: 593:
594: public function canInvoice()
595: {
596: if ($this->canUnhold() || $this->isPaymentReview()) {
597: return false;
598: }
599: $state = $this->getState();
600: if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
601: return false;
602: }
603:
604: if ($this->getActionFlag(self::ACTION_FLAG_INVOICE) === false) {
605: return false;
606: }
607:
608: foreach ($this->getAllItems() as $item) {
609: if ($item->getQtyToInvoice()>0 && !$item->getLockedDoInvoice()) {
610: return true;
611: }
612: }
613: return false;
614: }
615:
616: 617: 618: 619: 620:
621: public function canCreditmemo()
622: {
623: if ($this->hasForcedCanCreditmemo()) {
624: return $this->getForcedCanCreditmemo();
625: }
626:
627: if ($this->canUnhold() || $this->isPaymentReview()) {
628: return false;
629: }
630:
631: if ($this->isCanceled() || $this->getState() === self::STATE_CLOSED) {
632: return false;
633: }
634:
635: 636: 637: 638: 639:
640: if (abs($this->getStore()->roundPrice($this->getTotalPaid()) - $this->getTotalRefunded()) < .0001) {
641: return false;
642: }
643:
644: if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) {
645: return false;
646: }
647: return true;
648: }
649:
650: 651: 652: 653: 654:
655: public function canHold()
656: {
657: $state = $this->getState();
658: if ($this->isCanceled() || $this->isPaymentReview()
659: || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED || $state === self::STATE_HOLDED) {
660: return false;
661: }
662:
663: if ($this->getActionFlag(self::ACTION_FLAG_HOLD) === false) {
664: return false;
665: }
666: return true;
667: }
668:
669: 670: 671: 672: 673:
674: public function canUnhold()
675: {
676: if ($this->getActionFlag(self::ACTION_FLAG_UNHOLD) === false || $this->isPaymentReview()) {
677: return false;
678: }
679: return $this->getState() === self::STATE_HOLDED;
680: }
681:
682: 683: 684: 685: 686:
687: public function ()
688: {
689: if ($this->getActionFlag(self::ACTION_FLAG_COMMENT) === false) {
690: return false;
691: }
692: return true;
693: }
694:
695: 696: 697: 698: 699:
700: public function canShip()
701: {
702: if ($this->canUnhold() || $this->isPaymentReview()) {
703: return false;
704: }
705:
706: if ($this->getIsVirtual() || $this->isCanceled()) {
707: return false;
708: }
709:
710: if ($this->getActionFlag(self::ACTION_FLAG_SHIP) === false) {
711: return false;
712: }
713:
714: foreach ($this->getAllItems() as $item) {
715: if ($item->getQtyToShip()>0 && !$item->getIsVirtual()
716: && !$item->getLockedDoShip())
717: {
718: return true;
719: }
720: }
721: return false;
722: }
723:
724: 725: 726: 727: 728:
729: public function canEdit()
730: {
731: if ($this->canUnhold()) {
732: return false;
733: }
734:
735: $state = $this->getState();
736: if ($this->isCanceled() || $this->isPaymentReview()
737: || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
738: return false;
739: }
740:
741: if (!$this->getPayment()->getMethodInstance()->canEdit()) {
742: return false;
743: }
744:
745: if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) {
746: return false;
747: }
748:
749: return true;
750: }
751:
752: 753: 754: 755: 756:
757: public function canReorder()
758: {
759: return $this->_canReorder(false);
760: }
761:
762: 763: 764: 765: 766:
767: public function canReorderIgnoreSalable()
768: {
769: return $this->_canReorder(true);
770: }
771:
772: 773: 774: 775: 776: 777:
778: protected function _canReorder($ignoreSalable = false)
779: {
780: if ($this->canUnhold() || $this->isPaymentReview() || !$this->getCustomerId()) {
781: return false;
782: }
783:
784: $products = array();
785: foreach ($this->getItemsCollection() as $item) {
786: $products[] = $item->getProductId();
787: }
788:
789: if (!empty($products)) {
790: 791: 792: 793: 794: 795:
796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808:
809:
810: foreach ($products as $productId) {
811: $product = Mage::getModel('catalog/product')
812: ->setStoreId($this->getStoreId())
813: ->load($productId);
814: if (!$product->getId() || (!$ignoreSalable && !$product->isSalable())) {
815: return false;
816: }
817: }
818: }
819:
820: if ($this->getActionFlag(self::ACTION_FLAG_REORDER) === false) {
821: return false;
822: }
823:
824: return true;
825: }
826:
827: 828: 829: 830: 831: 832: 833: 834:
835: public function isPaymentReview()
836: {
837: return $this->getState() === self::STATE_PAYMENT_REVIEW;
838: }
839:
840: 841: 842: 843: 844:
845: public function canReviewPayment()
846: {
847: return $this->isPaymentReview() && $this->getPayment()->canReviewPayment();
848: }
849:
850: 851: 852: 853: 854:
855: public function canFetchPaymentReviewUpdate()
856: {
857: return $this->isPaymentReview() && $this->getPayment()->canFetchTransactionInfo();
858: }
859:
860: 861: 862: 863: 864:
865: public function getConfig()
866: {
867: return Mage::getSingleton('sales/order_config');
868: }
869:
870: 871: 872: 873: 874:
875: protected function _placePayment()
876: {
877: $this->getPayment()->place();
878: return $this;
879: }
880:
881: 882: 883: 884: 885:
886: public function getPayment()
887: {
888: foreach ($this->getPaymentsCollection() as $payment) {
889: if (!$payment->isDeleted()) {
890: return $payment;
891: }
892: }
893: return false;
894: }
895:
896: 897: 898: 899: 900: 901:
902: public function setBillingAddress(Mage_Sales_Model_Order_Address $address)
903: {
904: $old = $this->getBillingAddress();
905: if (!empty($old)) {
906: $address->setId($old->getId());
907: }
908: $this->addAddress($address->setAddressType('billing'));
909: return $this;
910: }
911:
912: 913: 914: 915: 916: 917:
918: public function setShippingAddress(Mage_Sales_Model_Order_Address $address)
919: {
920: $old = $this->getShippingAddress();
921: if (!empty($old)) {
922: $address->setId($old->getId());
923: }
924: $this->addAddress($address->setAddressType('shipping'));
925: return $this;
926: }
927:
928: 929: 930: 931: 932:
933: public function getBillingAddress()
934: {
935: foreach ($this->getAddressesCollection() as $address) {
936: if ($address->getAddressType()=='billing' && !$address->isDeleted()) {
937: return $address;
938: }
939: }
940: return false;
941: }
942:
943: 944: 945: 946: 947:
948: public function getShippingAddress()
949: {
950: foreach ($this->getAddressesCollection() as $address) {
951: if ($address->getAddressType()=='shipping' && !$address->isDeleted()) {
952: return $address;
953: }
954: }
955: return false;
956: }
957:
958: 959: 960: 961: 962: 963: 964: 965: 966: 967: 968:
969: public function setState($state, $status = false, $comment = '', $isCustomerNotified = null)
970: {
971: return $this->_setState($state, $status, $comment, $isCustomerNotified, true);
972: }
973:
974: 975: 976: 977: 978: 979: 980: 981: 982: 983: 984: 985:
986: protected function _setState($state, $status = false, $comment = '',
987: $isCustomerNotified = null, $shouldProtectState = false)
988: {
989:
990: if ($shouldProtectState) {
991: if ($this->isStateProtected($state)) {
992: Mage::throwException(
993: Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state)
994: );
995: }
996: }
997: $this->setData('state', $state);
998:
999:
1000: if ($status) {
1001: if ($status === true) {
1002: $status = $this->getConfig()->getStateDefaultStatus($state);
1003: }
1004: $this->setStatus($status);
1005: $history = $this->addStatusHistoryComment($comment, false);
1006: $history->setIsCustomerNotified($isCustomerNotified);
1007: }
1008: return $this;
1009: }
1010:
1011: 1012: 1013: 1014: 1015:
1016: public function isStateProtected($state)
1017: {
1018: if (empty($state)) {
1019: return false;
1020: }
1021: return self::STATE_COMPLETE == $state || self::STATE_CLOSED == $state;
1022: }
1023:
1024: 1025: 1026: 1027: 1028:
1029: public function getStatusLabel()
1030: {
1031: return $this->getConfig()->getStatusLabel($this->getStatus());
1032: }
1033:
1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042:
1043: public function addStatusToHistory($status, $comment = '', $isCustomerNotified = false)
1044: {
1045: $history = $this->addStatusHistoryComment($comment, $status)
1046: ->setIsCustomerNotified($isCustomerNotified);
1047: return $this;
1048: }
1049:
1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057:
1058: public function ($comment, $status = false)
1059: {
1060: if (false === $status) {
1061: $status = $this->getStatus();
1062: } elseif (true === $status) {
1063: $status = $this->getConfig()->getStateDefaultStatus($this->getState());
1064: } else {
1065: $this->setStatus($status);
1066: }
1067: $history = Mage::getModel('sales/order_status_history')
1068: ->setStatus($status)
1069: ->setComment($comment)
1070: ->setEntityName($this->_historyEntityName);
1071: $this->addStatusHistory($history);
1072: return $history;
1073: }
1074:
1075: 1076: 1077: 1078: 1079: 1080:
1081: public function setHistoryEntityName( $entityName )
1082: {
1083: $this->_historyEntityName = $entityName;
1084: return $this;
1085: }
1086:
1087: 1088: 1089: 1090: 1091:
1092: public function place()
1093: {
1094: Mage::dispatchEvent('sales_order_place_before', array('order'=>$this));
1095: $this->_placePayment();
1096: Mage::dispatchEvent('sales_order_place_after', array('order'=>$this));
1097: return $this;
1098: }
1099:
1100: public function hold()
1101: {
1102: if (!$this->canHold()) {
1103: Mage::throwException(Mage::helper('sales')->__('Hold action is not available.'));
1104: }
1105: $this->setHoldBeforeState($this->getState());
1106: $this->setHoldBeforeStatus($this->getStatus());
1107: $this->setState(self::STATE_HOLDED, true);
1108: return $this;
1109: }
1110:
1111: 1112: 1113: 1114: 1115: 1116:
1117: public function unhold()
1118: {
1119: if (!$this->canUnhold()) {
1120: Mage::throwException(Mage::helper('sales')->__('Unhold action is not available.'));
1121: }
1122: $this->setState($this->getHoldBeforeState(), $this->getHoldBeforeStatus());
1123: $this->setHoldBeforeState(null);
1124: $this->setHoldBeforeStatus(null);
1125: return $this;
1126: }
1127:
1128: 1129: 1130: 1131: 1132:
1133: public function cancel()
1134: {
1135: if ($this->canCancel()) {
1136: $this->getPayment()->cancel();
1137: $this->registerCancellation();
1138:
1139: Mage::dispatchEvent('order_cancel_after', array('order' => $this));
1140: }
1141:
1142: return $this;
1143: }
1144:
1145: 1146: 1147: 1148: 1149: 1150: 1151:
1152: public function registerCancellation($comment = '', $graceful = true)
1153: {
1154: if ($this->canCancel()) {
1155: $cancelState = self::STATE_CANCELED;
1156: foreach ($this->getAllItems() as $item) {
1157: if ($cancelState != self::STATE_PROCESSING && $item->getQtyToRefund()) {
1158: if ($item->getQtyToShip() > $item->getQtyToCancel()) {
1159: $cancelState = self::STATE_PROCESSING;
1160: } else {
1161: $cancelState = self::STATE_COMPLETE;
1162: }
1163: }
1164: $item->cancel();
1165: }
1166:
1167: $this->setSubtotalCanceled($this->getSubtotal() - $this->getSubtotalInvoiced());
1168: $this->setBaseSubtotalCanceled($this->getBaseSubtotal() - $this->getBaseSubtotalInvoiced());
1169:
1170: $this->setTaxCanceled($this->getTaxAmount() - $this->getTaxInvoiced());
1171: $this->setBaseTaxCanceled($this->getBaseTaxAmount() - $this->getBaseTaxInvoiced());
1172:
1173: $this->setShippingCanceled($this->getShippingAmount() - $this->getShippingInvoiced());
1174: $this->setBaseShippingCanceled($this->getBaseShippingAmount() - $this->getBaseShippingInvoiced());
1175:
1176: $this->setDiscountCanceled(abs($this->getDiscountAmount()) - $this->getDiscountInvoiced());
1177: $this->setBaseDiscountCanceled(abs($this->getBaseDiscountAmount()) - $this->getBaseDiscountInvoiced());
1178:
1179: $this->setTotalCanceled($this->getGrandTotal() - $this->getTotalPaid());
1180: $this->setBaseTotalCanceled($this->getBaseGrandTotal() - $this->getBaseTotalPaid());
1181:
1182: $this->_setState($cancelState, true, $comment);
1183: } elseif (!$graceful) {
1184: Mage::throwException(Mage::helper('sales')->__('Order does not allow to be canceled.'));
1185: }
1186: return $this;
1187: }
1188:
1189: 1190: 1191: 1192: 1193:
1194: public function getTrackingNumbers()
1195: {
1196: if ($this->getData('tracking_numbers')) {
1197: return explode(',', $this->getData('tracking_numbers'));
1198: }
1199: return array();
1200: }
1201:
1202: 1203: 1204: 1205: 1206:
1207: public function getShippingCarrier()
1208: {
1209: $carrierModel = $this->getData('shipping_carrier');
1210: if (is_null($carrierModel)) {
1211: $carrierModel = false;
1212: 1213: 1214:
1215: $method = $this->getShippingMethod(true);
1216: if ($method instanceof Varien_Object) {
1217: $className = Mage::getStoreConfig('carriers/' . $method->getCarrierCode() . '/model');
1218: if ($className) {
1219: $carrierModel = Mage::getModel($className);
1220: }
1221: }
1222: $this->setData('shipping_carrier', $carrierModel);
1223: }
1224: return $carrierModel;
1225: }
1226:
1227: 1228: 1229: 1230: 1231: 1232:
1233: public function getShippingMethod($asObject = false)
1234: {
1235: $shippingMethod = parent::getShippingMethod();
1236: if (!$asObject) {
1237: return $shippingMethod;
1238: } else {
1239: list($carrierCode, $method) = explode('_', $shippingMethod, 2);
1240: return new Varien_Object(array(
1241: 'carrier_code' => $carrierCode,
1242: 'method' => $method
1243: ));
1244: }
1245: }
1246:
1247: 1248: 1249: 1250: 1251:
1252: public function sendNewOrderEmail()
1253: {
1254: $storeId = $this->getStore()->getId();
1255:
1256: if (!Mage::helper('sales')->canSendNewOrderEmail($storeId)) {
1257: return $this;
1258: }
1259:
1260: $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
1261: $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
1262:
1263:
1264: $appEmulation = Mage::getSingleton('core/app_emulation');
1265: $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
1266:
1267: try {
1268:
1269: $paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
1270: ->setIsSecureMode(true);
1271: $paymentBlock->getMethod()->setStore($storeId);
1272: $paymentBlockHtml = $paymentBlock->toHtml();
1273: } catch (Exception $exception) {
1274:
1275: $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1276: throw $exception;
1277: }
1278:
1279:
1280: $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1281:
1282:
1283: if ($this->getCustomerIsGuest()) {
1284: $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
1285: $customerName = $this->getBillingAddress()->getName();
1286: } else {
1287: $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
1288: $customerName = $this->getCustomerName();
1289: }
1290:
1291: $mailer = Mage::getModel('core/email_template_mailer');
1292: $emailInfo = Mage::getModel('core/email_info');
1293: $emailInfo->addTo($this->getCustomerEmail(), $customerName);
1294: if ($copyTo && $copyMethod == 'bcc') {
1295:
1296: foreach ($copyTo as $email) {
1297: $emailInfo->addBcc($email);
1298: }
1299: }
1300: $mailer->addEmailInfo($emailInfo);
1301:
1302:
1303: if ($copyTo && $copyMethod == 'copy') {
1304: foreach ($copyTo as $email) {
1305: $emailInfo = Mage::getModel('core/email_info');
1306: $emailInfo->addTo($email);
1307: $mailer->addEmailInfo($emailInfo);
1308: }
1309: }
1310:
1311:
1312: $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
1313: $mailer->setStoreId($storeId);
1314: $mailer->setTemplateId($templateId);
1315: $mailer->setTemplateParams(array(
1316: 'order' => $this,
1317: 'billing' => $this->getBillingAddress(),
1318: 'payment_html' => $paymentBlockHtml
1319: )
1320: );
1321: $mailer->send();
1322:
1323: $this->setEmailSent(true);
1324: $this->_getResource()->saveAttribute($this, 'email_sent');
1325:
1326: return $this;
1327: }
1328:
1329: 1330: 1331: 1332: 1333: 1334: 1335:
1336: public function sendOrderUpdateEmail($notifyCustomer = true, $comment = '')
1337: {
1338: $storeId = $this->getStore()->getId();
1339:
1340: if (!Mage::helper('sales')->canSendOrderCommentEmail($storeId)) {
1341: return $this;
1342: }
1343:
1344: $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO);
1345: $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $storeId);
1346:
1347: if (!$notifyCustomer && !$copyTo) {
1348: return $this;
1349: }
1350:
1351:
1352: if ($this->getCustomerIsGuest()) {
1353: $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $storeId);
1354: $customerName = $this->getBillingAddress()->getName();
1355: } else {
1356: $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $storeId);
1357: $customerName = $this->getCustomerName();
1358: }
1359:
1360: $mailer = Mage::getModel('core/email_template_mailer');
1361: if ($notifyCustomer) {
1362: $emailInfo = Mage::getModel('core/email_info');
1363: $emailInfo->addTo($this->getCustomerEmail(), $customerName);
1364: if ($copyTo && $copyMethod == 'bcc') {
1365:
1366: foreach ($copyTo as $email) {
1367: $emailInfo->addBcc($email);
1368: }
1369: }
1370: $mailer->addEmailInfo($emailInfo);
1371: }
1372:
1373:
1374:
1375: if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) {
1376: foreach ($copyTo as $email) {
1377: $emailInfo = Mage::getModel('core/email_info');
1378: $emailInfo->addTo($email);
1379: $mailer->addEmailInfo($emailInfo);
1380: }
1381: }
1382:
1383:
1384: $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $storeId));
1385: $mailer->setStoreId($storeId);
1386: $mailer->setTemplateId($templateId);
1387: $mailer->setTemplateParams(array(
1388: 'order' => $this,
1389: 'comment' => $comment,
1390: 'billing' => $this->getBillingAddress()
1391: )
1392: );
1393: $mailer->send();
1394:
1395: return $this;
1396: }
1397:
1398: protected function _getEmails($configPath)
1399: {
1400: $data = Mage::getStoreConfig($configPath, $this->getStoreId());
1401: if (!empty($data)) {
1402: return explode(',', $data);
1403: }
1404: return false;
1405: }
1406:
1407:
1408:
1409: public function getAddressesCollection()
1410: {
1411: if (is_null($this->_addresses)) {
1412: $this->_addresses = Mage::getResourceModel('sales/order_address_collection')
1413: ->setOrderFilter($this);
1414:
1415: if ($this->getId()) {
1416: foreach ($this->_addresses as $address) {
1417: $address->setOrder($this);
1418: }
1419: }
1420: }
1421:
1422: return $this->_addresses;
1423: }
1424:
1425: public function getAddressById($addressId)
1426: {
1427: foreach ($this->getAddressesCollection() as $address) {
1428: if ($address->getId()==$addressId) {
1429: return $address;
1430: }
1431: }
1432: return false;
1433: }
1434:
1435: public function addAddress(Mage_Sales_Model_Order_Address $address)
1436: {
1437: $address->setOrder($this)->setParentId($this->getId());
1438: if (!$address->getId()) {
1439: $this->getAddressesCollection()->addItem($address);
1440: }
1441: return $this;
1442: }
1443:
1444: public function getItemsCollection($filterByTypes = array(), $nonChildrenOnly = false)
1445: {
1446: if (is_null($this->_items)) {
1447: $this->_items = Mage::getResourceModel('sales/order_item_collection')
1448: ->setOrderFilter($this);
1449:
1450: if ($filterByTypes) {
1451: $this->_items->filterByTypes($filterByTypes);
1452: }
1453: if ($nonChildrenOnly) {
1454: $this->_items->filterByParent();
1455: }
1456:
1457: if ($this->getId()) {
1458: foreach ($this->_items as $item) {
1459: $item->setOrder($this);
1460: }
1461: }
1462: }
1463: return $this->_items;
1464: }
1465:
1466: 1467: 1468: 1469: 1470: 1471:
1472: public function getItemsRandomCollection($limit = 1)
1473: {
1474: return $this->_getItemsRandomCollection($limit);
1475: }
1476:
1477: 1478: 1479: 1480: 1481: 1482:
1483: public function getParentItemsRandomCollection($limit = 1)
1484: {
1485: return $this->_getItemsRandomCollection($limit, true);
1486: }
1487:
1488: 1489: 1490: 1491: 1492: 1493: 1494:
1495: protected function _getItemsRandomCollection($limit, $nonChildrenOnly = false)
1496: {
1497: $collection = Mage::getModel('sales/order_item')->getCollection()
1498: ->setOrderFilter($this)
1499: ->setRandomOrder();
1500:
1501: if ($nonChildrenOnly) {
1502: $collection->filterByParent();
1503: }
1504: $products = array();
1505: foreach ($collection as $item) {
1506: $products[] = $item->getProductId();
1507: }
1508:
1509: $productsCollection = Mage::getModel('catalog/product')
1510: ->getCollection()
1511: ->addIdFilter($products)
1512: ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds())
1513:
1514: ->addPriceData()
1515: ->setPageSize($limit)
1516: ->load();
1517:
1518: foreach ($collection as $item) {
1519: $product = $productsCollection->getItemById($item->getProductId());
1520: if ($product) {
1521: $item->setProduct($product);
1522: }
1523: }
1524:
1525: return $collection;
1526: }
1527:
1528: public function getAllItems()
1529: {
1530: $items = array();
1531: foreach ($this->getItemsCollection() as $item) {
1532: if (!$item->isDeleted()) {
1533: $items[] = $item;
1534: }
1535: }
1536: return $items;
1537: }
1538:
1539: public function getAllVisibleItems()
1540: {
1541: $items = array();
1542: foreach ($this->getItemsCollection() as $item) {
1543: if (!$item->isDeleted() && !$item->getParentItemId()) {
1544: $items[] = $item;
1545: }
1546: }
1547: return $items;
1548: }
1549:
1550: public function getItemById($itemId)
1551: {
1552: return $this->getItemsCollection()->getItemById($itemId);
1553: }
1554:
1555: public function getItemByQuoteItemId($quoteItemId)
1556: {
1557: foreach ($this->getItemsCollection() as $item) {
1558: if ($item->getQuoteItemId()==$quoteItemId) {
1559: return $item;
1560: }
1561: }
1562: return null;
1563: }
1564:
1565: public function addItem(Mage_Sales_Model_Order_Item $item)
1566: {
1567: $item->setOrder($this);
1568: if (!$item->getId()) {
1569: $this->getItemsCollection()->addItem($item);
1570: }
1571: return $this;
1572: }
1573:
1574: 1575: 1576: 1577: 1578:
1579: public function isNominal()
1580: {
1581: foreach ($this->getAllVisibleItems() as $item) {
1582: if ('0' == $item->getIsNominal()) {
1583: return false;
1584: }
1585: }
1586: return true;
1587: }
1588:
1589:
1590:
1591: public function getPaymentsCollection()
1592: {
1593: if (is_null($this->_payments)) {
1594: $this->_payments = Mage::getResourceModel('sales/order_payment_collection')
1595: ->setOrderFilter($this);
1596:
1597: if ($this->getId()) {
1598: foreach ($this->_payments as $payment) {
1599: $payment->setOrder($this);
1600: }
1601: }
1602: }
1603: return $this->_payments;
1604: }
1605:
1606: public function getAllPayments()
1607: {
1608: $payments = array();
1609: foreach ($this->getPaymentsCollection() as $payment) {
1610: if (!$payment->isDeleted()) {
1611: $payments[] = $payment;
1612: }
1613: }
1614: return $payments;
1615: }
1616:
1617:
1618: public function getPaymentById($paymentId)
1619: {
1620: foreach ($this->getPaymentsCollection() as $payment) {
1621: if ($payment->getId()==$paymentId) {
1622: return $payment;
1623: }
1624: }
1625: return false;
1626: }
1627:
1628: public function addPayment(Mage_Sales_Model_Order_Payment $payment)
1629: {
1630: $payment->setOrder($this)
1631: ->setParentId($this->getId());
1632: if (!$payment->getId()) {
1633: $this->getPaymentsCollection()->addItem($payment);
1634: }
1635: return $this;
1636: }
1637:
1638: public function setPayment(Mage_Sales_Model_Order_Payment $payment)
1639: {
1640: if (!$this->getIsMultiPayment() && ($old = $this->getPayment())) {
1641: $payment->setId($old->getId());
1642: }
1643: $this->addPayment($payment);
1644: return $payment;
1645: }
1646:
1647:
1648:
1649: 1650: 1651: 1652: 1653:
1654: public function getStatusHistoryCollection($reload=false)
1655: {
1656: if (is_null($this->_statusHistory) || $reload) {
1657: $this->_statusHistory = Mage::getResourceModel('sales/order_status_history_collection')
1658: ->setOrderFilter($this)
1659: ->setOrder('created_at', 'desc')
1660: ->setOrder('entity_id', 'desc');
1661:
1662: if ($this->getId()) {
1663: foreach ($this->_statusHistory as $status) {
1664: $status->setOrder($this);
1665: }
1666: }
1667: }
1668: return $this->_statusHistory;
1669: }
1670:
1671: 1672: 1673: 1674: 1675:
1676: public function getAllStatusHistory()
1677: {
1678: $history = array();
1679: foreach ($this->getStatusHistoryCollection() as $status) {
1680: if (!$status->isDeleted()) {
1681: $history[] = $status;
1682: }
1683: }
1684: return $history;
1685: }
1686:
1687: 1688: 1689: 1690: 1691:
1692: public function getVisibleStatusHistory()
1693: {
1694: $history = array();
1695: foreach ($this->getStatusHistoryCollection() as $status) {
1696: if (!$status->isDeleted() && $status->getComment() && $status->getIsVisibleOnFront()) {
1697: $history[] = $status;
1698: }
1699: }
1700: return $history;
1701: }
1702:
1703: public function getStatusHistoryById($statusId)
1704: {
1705: foreach ($this->getStatusHistoryCollection() as $status) {
1706: if ($status->getId()==$statusId) {
1707: return $status;
1708: }
1709: }
1710: return false;
1711: }
1712:
1713: 1714: 1715: 1716: 1717: 1718: 1719: 1720: 1721:
1722: public function addStatusHistory(Mage_Sales_Model_Order_Status_History $history)
1723: {
1724: $history->setOrder($this);
1725: $this->setStatus($history->getStatus());
1726: if (!$history->getId()) {
1727: $this->getStatusHistoryCollection()->addItem($history);
1728: }
1729: return $this;
1730: }
1731:
1732:
1733: 1734: 1735: 1736: 1737:
1738: public function getRealOrderId()
1739: {
1740: $id = $this->getData('real_order_id');
1741: if (is_null($id)) {
1742: $id = $this->getIncrementId();
1743: }
1744: return $id;
1745: }
1746:
1747: 1748: 1749: 1750: 1751:
1752: public function getOrderCurrency()
1753: {
1754: if (is_null($this->_orderCurrency)) {
1755: $this->_orderCurrency = Mage::getModel('directory/currency')->load($this->getOrderCurrencyCode());
1756: }
1757: return $this->_orderCurrency;
1758: }
1759:
1760: 1761: 1762: 1763: 1764: 1765: 1766:
1767: public function formatPrice($price, $addBrackets = false)
1768: {
1769: return $this->formatPricePrecision($price, 2, $addBrackets);
1770: }
1771:
1772: public function formatPricePrecision($price, $precision, $addBrackets = false)
1773: {
1774: return $this->getOrderCurrency()->formatPrecision($price, $precision, array(), true, $addBrackets);
1775: }
1776:
1777: 1778: 1779: 1780: 1781: 1782:
1783: public function formatPriceTxt($price)
1784: {
1785: return $this->getOrderCurrency()->formatTxt($price);
1786: }
1787:
1788: 1789: 1790: 1791: 1792:
1793: public function getBaseCurrency()
1794: {
1795: if (is_null($this->_baseCurrency)) {
1796: $this->_baseCurrency = Mage::getModel('directory/currency')->load($this->getBaseCurrencyCode());
1797: }
1798: return $this->_baseCurrency;
1799: }
1800:
1801: 1802: 1803: 1804: 1805: 1806:
1807: public function getStoreCurrency()
1808: {
1809: return $this->getData('store_currency');
1810: }
1811:
1812: public function formatBasePrice($price)
1813: {
1814: return $this->formatBasePricePrecision($price, 2);
1815: }
1816:
1817: public function formatBasePricePrecision($price, $precision)
1818: {
1819: return $this->getBaseCurrency()->formatPrecision($price, $precision);
1820: }
1821:
1822: public function isCurrencyDifferent()
1823: {
1824: return $this->getOrderCurrencyCode() != $this->getBaseCurrencyCode();
1825: }
1826:
1827: 1828: 1829: 1830: 1831:
1832: public function getTotalDue()
1833: {
1834: $total = $this->getGrandTotal()-$this->getTotalPaid();
1835: $total = Mage::app()->getStore($this->getStoreId())->roundPrice($total);
1836: return max($total, 0);
1837: }
1838:
1839: 1840: 1841: 1842: 1843:
1844: public function getBaseTotalDue()
1845: {
1846: $total = $this->getBaseGrandTotal()-$this->getBaseTotalPaid();
1847: $total = Mage::app()->getStore($this->getStoreId())->roundPrice($total);
1848: return max($total, 0);
1849: }
1850:
1851: public function getData($key='', $index=null)
1852: {
1853: if ($key == 'total_due') {
1854: return $this->getTotalDue();
1855: }
1856: if ($key == 'base_total_due') {
1857: return $this->getBaseTotalDue();
1858: }
1859: return parent::getData($key, $index);
1860: }
1861:
1862: 1863: 1864: 1865: 1866:
1867: public function getInvoiceCollection()
1868: {
1869: if (is_null($this->_invoices)) {
1870: $this->_invoices = Mage::getResourceModel('sales/order_invoice_collection')
1871: ->setOrderFilter($this);
1872:
1873: if ($this->getId()) {
1874: foreach ($this->_invoices as $invoice) {
1875: $invoice->setOrder($this);
1876: }
1877: }
1878: }
1879: return $this->_invoices;
1880: }
1881:
1882: 1883: 1884: 1885: 1886:
1887: public function getShipmentsCollection()
1888: {
1889: if (empty($this->_shipments)) {
1890: if ($this->getId()) {
1891: $this->_shipments = Mage::getResourceModel('sales/order_shipment_collection')
1892: ->setOrderFilter($this)
1893: ->load();
1894: } else {
1895: return false;
1896: }
1897: }
1898: return $this->_shipments;
1899: }
1900:
1901: 1902: 1903: 1904: 1905:
1906: public function getCreditmemosCollection()
1907: {
1908: if (empty($this->_creditmemos)) {
1909: if ($this->getId()) {
1910: $this->_creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')
1911: ->setOrderFilter($this)
1912: ->load();
1913: } else {
1914: return false;
1915: }
1916: }
1917: return $this->_creditmemos;
1918: }
1919:
1920: 1921: 1922: 1923: 1924:
1925: public function getTracksCollection()
1926: {
1927: if (empty($this->_tracks)) {
1928: $this->_tracks = Mage::getResourceModel('sales/order_shipment_track_collection')
1929: ->setOrderFilter($this);
1930:
1931: if ($this->getId()) {
1932: $this->_tracks->load();
1933: }
1934: }
1935: return $this->_tracks;
1936: }
1937:
1938: 1939: 1940: 1941: 1942:
1943: public function hasInvoices()
1944: {
1945: return $this->getInvoiceCollection()->count();
1946: }
1947:
1948: 1949: 1950: 1951: 1952:
1953: public function hasShipments()
1954: {
1955: return $this->getShipmentsCollection()->count();
1956: }
1957:
1958: 1959: 1960: 1961: 1962:
1963: public function hasCreditmemos()
1964: {
1965: return $this->getCreditmemosCollection()->count();
1966: }
1967:
1968:
1969: 1970: 1971: 1972: 1973: 1974: 1975:
1976: public function getRelatedObjects()
1977: {
1978: return $this->_relatedObjects;
1979: }
1980:
1981: public function getCustomerName()
1982: {
1983: if ($this->getCustomerFirstname()) {
1984: $customerName = $this->getCustomerFirstname() . ' ' . $this->getCustomerLastname();
1985: }
1986: else {
1987: $customerName = Mage::helper('sales')->__('Guest');
1988: }
1989: return $customerName;
1990: }
1991:
1992: 1993: 1994: 1995: 1996: 1997:
1998: public function addRelatedObject(Mage_Core_Model_Abstract $object)
1999: {
2000: $this->_relatedObjects[] = $object;
2001: return $this;
2002: }
2003:
2004: 2005: 2006: 2007: 2008: 2009:
2010: public function getCreatedAtFormated($format)
2011: {
2012: return Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format, true);
2013: }
2014:
2015: public function getEmailCustomerNote()
2016: {
2017: if ($this->getCustomerNoteNotify()) {
2018: return $this->getCustomerNote();
2019: }
2020: return '';
2021: }
2022:
2023: 2024: 2025: 2026: 2027:
2028: protected function _beforeSave()
2029: {
2030: parent::_beforeSave();
2031: $this->_checkState();
2032: if (!$this->getId()) {
2033: $store = $this->getStore();
2034: $name = array($store->getWebsite()->getName(),$store->getGroup()->getName(),$store->getName());
2035: $this->setStoreName(implode("\n", $name));
2036: }
2037:
2038: if (!$this->getIncrementId()) {
2039: $incrementId = Mage::getSingleton('eav/config')
2040: ->getEntityType('order')
2041: ->fetchNewIncrementId($this->getStoreId());
2042: $this->setIncrementId($incrementId);
2043: }
2044:
2045: 2046: 2047:
2048: if (!$this->getId()) {
2049: $itemsCount = 0;
2050: foreach ($this->getAllItems() as $item) {
2051: $parent = $item->getQuoteParentItemId();
2052: if ($parent && !$item->getParentItem()) {
2053: $item->setParentItem($this->getItemByQuoteItemId($parent));
2054: } elseif (!$parent) {
2055: $itemsCount++;
2056: }
2057: }
2058:
2059: $this->setTotalItemCount($itemsCount);
2060: }
2061: if ($this->getCustomer()) {
2062: $this->setCustomerId($this->getCustomer()->getId());
2063: }
2064:
2065: if ($this->hasBillingAddressId() && $this->getBillingAddressId() === null) {
2066: $this->unsBillingAddressId();
2067: }
2068:
2069: if ($this->hasShippingAddressId() && $this->getShippingAddressId() === null) {
2070: $this->unsShippingAddressId();
2071: }
2072:
2073: $this->setData('protect_code', substr(md5(uniqid(mt_rand(), true) . ':' . microtime(true)), 5, 6));
2074: return $this;
2075: }
2076:
2077: 2078: 2079:
2080: protected function _checkState()
2081: {
2082: if (!$this->getId()) {
2083: return $this;
2084: }
2085:
2086: $userNotification = $this->hasCustomerNoteNotify() ? $this->getCustomerNoteNotify() : null;
2087:
2088: if (!$this->isCanceled()
2089: && !$this->canUnhold()
2090: && !$this->canInvoice()
2091: && !$this->canShip()) {
2092: if (0 == $this->getBaseGrandTotal() || $this->canCreditmemo()) {
2093: if ($this->getState() !== self::STATE_COMPLETE) {
2094: $this->_setState(self::STATE_COMPLETE, true, '', $userNotification);
2095: }
2096: }
2097: 2098: 2099: 2100:
2101: elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded()
2102: && $this->hasForcedCanCreditmemo())
2103: ) {
2104: if ($this->getState() !== self::STATE_CLOSED) {
2105: $this->_setState(self::STATE_CLOSED, true, '', $userNotification);
2106: }
2107: }
2108: }
2109:
2110: if ($this->getState() == self::STATE_NEW && $this->getIsInProcess()) {
2111: $this->setState(self::STATE_PROCESSING, true, '', $userNotification);
2112: }
2113: return $this;
2114: }
2115:
2116: 2117: 2118: 2119: 2120:
2121: protected function _afterSave()
2122: {
2123: if (null !== $this->_addresses) {
2124: $this->_addresses->save();
2125: $billingAddress = $this->getBillingAddress();
2126: $attributesForSave = array();
2127: if ($billingAddress && $this->getBillingAddressId() != $billingAddress->getId()) {
2128: $this->setBillingAddressId($billingAddress->getId());
2129: $attributesForSave[] = 'billing_address_id';
2130: }
2131:
2132: $shippingAddress = $this->getShippingAddress();
2133: if ($shippingAddress && $this->getShippigAddressId() != $shippingAddress->getId()) {
2134: $this->setShippingAddressId($shippingAddress->getId());
2135: $attributesForSave[] = 'shipping_address_id';
2136: }
2137:
2138: if (!empty($attributesForSave)) {
2139: $this->_getResource()->saveAttribute($this, $attributesForSave);
2140: }
2141:
2142: }
2143: if (null !== $this->_items) {
2144: $this->_items->save();
2145: }
2146: if (null !== $this->_payments) {
2147: $this->_payments->save();
2148: }
2149: if (null !== $this->_statusHistory) {
2150: $this->_statusHistory->save();
2151: }
2152: foreach ($this->getRelatedObjects() as $object) {
2153: $object->save();
2154: }
2155: return parent::_afterSave();
2156: }
2157:
2158: public function getStoreGroupName()
2159: {
2160: $storeId = $this->getStoreId();
2161: if (is_null($storeId)) {
2162: return $this->getStoreName(1);
2163: }
2164: return $this->getStore()->getGroup()->getName();
2165: }
2166:
2167: 2168: 2169: 2170: 2171: 2172:
2173: public function reset()
2174: {
2175: $this->unsetData();
2176: $this->_actionFlag = array();
2177: $this->_addresses = null;
2178: $this->_items = null;
2179: $this->_payments = null;
2180: $this->_statusHistory = null;
2181: $this->_invoices = null;
2182: $this->_tracks = null;
2183: $this->_shipments = null;
2184: $this->_creditmemos = null;
2185: $this->_relatedObjects = array();
2186: $this->_orderCurrency = null;
2187: $this->_baseCurrency = null;
2188:
2189: return $this;
2190: }
2191:
2192: public function getIsNotVirtual()
2193: {
2194: return !$this->getIsVirtual();
2195: }
2196:
2197: public function getFullTaxInfo()
2198: {
2199: $rates = Mage::getModel('tax/sales_order_tax')->getCollection()->loadByOrder($this)->toArray();
2200: return Mage::getSingleton('tax/calculation')->reproduceProcess($rates['items']);
2201: }
2202:
2203: 2204: 2205: 2206: 2207:
2208: public function prepareInvoice($qtys = array())
2209: {
2210: $invoice = Mage::getModel('sales/service_order', $this)->prepareInvoice($qtys);
2211: return $invoice;
2212: }
2213:
2214: 2215: 2216: 2217: 2218:
2219: public function prepareShipment($qtys = array())
2220: {
2221: $shipment = Mage::getModel('sales/service_order', $this)->prepareShipment($qtys);
2222: return $shipment;
2223: }
2224:
2225: 2226: 2227: 2228: 2229:
2230: public function isCanceled()
2231: {
2232: return ($this->getState() === self::STATE_CANCELED);
2233: }
2234:
2235: 2236: 2237: 2238:
2239: protected function _beforeDelete()
2240: {
2241: $this->_protectFromNonAdmin();
2242: return parent::_beforeDelete();
2243: }
2244: }
2245: