/
Order.php
2317 lines (2109 loc) · 73 KB
/
Order.php
1
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Sales
<<<<<<< HEAD
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
=======
* @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
>>>>>>> origin/master
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Order model
*
* Supported events:
* sales_order_load_after
* sales_order_save_before
* sales_order_save_after
* sales_order_delete_before
* sales_order_delete_after
*
* @method Mage_Sales_Model_Resource_Order _getResource()
* @method Mage_Sales_Model_Resource_Order getResource()
* @method string getState()
* @method string getStatus()
* @method Mage_Sales_Model_Order setStatus(string $value)
* @method string getCouponCode()
* @method Mage_Sales_Model_Order setCouponCode(string $value)
* @method string getProtectCode()
* @method Mage_Sales_Model_Order setProtectCode(string $value)
* @method string getShippingDescription()
* @method Mage_Sales_Model_Order setShippingDescription(string $value)
* @method int getIsVirtual()
* @method Mage_Sales_Model_Order setIsVirtual(int $value)
* @method int getStoreId()
* @method Mage_Sales_Model_Order setStoreId(int $value)
* @method int getCustomerId()
* @method Mage_Sales_Model_Order setCustomerId(int $value)
* @method float getBaseDiscountAmount()
* @method Mage_Sales_Model_Order setBaseDiscountAmount(float $value)
* @method float getBaseDiscountCanceled()
* @method Mage_Sales_Model_Order setBaseDiscountCanceled(float $value)
* @method float getBaseDiscountInvoiced()
* @method Mage_Sales_Model_Order setBaseDiscountInvoiced(float $value)
* @method float getBaseDiscountRefunded()
* @method Mage_Sales_Model_Order setBaseDiscountRefunded(float $value)
* @method float getBaseGrandTotal()
* @method Mage_Sales_Model_Order setBaseGrandTotal(float $value)
* @method float getBaseShippingAmount()
* @method Mage_Sales_Model_Order setBaseShippingAmount(float $value)
* @method float getBaseShippingCanceled()
* @method Mage_Sales_Model_Order setBaseShippingCanceled(float $value)
* @method float getBaseShippingInvoiced()
* @method Mage_Sales_Model_Order setBaseShippingInvoiced(float $value)
* @method float getBaseShippingRefunded()
* @method Mage_Sales_Model_Order setBaseShippingRefunded(float $value)
* @method float getBaseShippingTaxAmount()
* @method Mage_Sales_Model_Order setBaseShippingTaxAmount(float $value)
* @method float getBaseShippingTaxRefunded()
* @method Mage_Sales_Model_Order setBaseShippingTaxRefunded(float $value)
* @method float getBaseSubtotal()
* @method Mage_Sales_Model_Order setBaseSubtotal(float $value)
* @method float getBaseSubtotalCanceled()
* @method Mage_Sales_Model_Order setBaseSubtotalCanceled(float $value)
* @method float getBaseSubtotalInvoiced()
* @method Mage_Sales_Model_Order setBaseSubtotalInvoiced(float $value)
* @method float getBaseSubtotalRefunded()
* @method Mage_Sales_Model_Order setBaseSubtotalRefunded(float $value)
* @method float getBaseTaxAmount()
* @method Mage_Sales_Model_Order setBaseTaxAmount(float $value)
* @method float getBaseTaxCanceled()
* @method Mage_Sales_Model_Order setBaseTaxCanceled(float $value)
* @method float getBaseTaxInvoiced()
* @method Mage_Sales_Model_Order setBaseTaxInvoiced(float $value)
* @method float getBaseTaxRefunded()
* @method Mage_Sales_Model_Order setBaseTaxRefunded(float $value)
* @method float getBaseToGlobalRate()
* @method Mage_Sales_Model_Order setBaseToGlobalRate(float $value)
* @method float getBaseToOrderRate()
* @method Mage_Sales_Model_Order setBaseToOrderRate(float $value)
* @method float getBaseTotalCanceled()
* @method Mage_Sales_Model_Order setBaseTotalCanceled(float $value)
* @method float getBaseTotalInvoiced()
* @method Mage_Sales_Model_Order setBaseTotalInvoiced(float $value)
* @method float getBaseTotalInvoicedCost()
* @method Mage_Sales_Model_Order setBaseTotalInvoicedCost(float $value)
* @method float getBaseTotalOfflineRefunded()
* @method Mage_Sales_Model_Order setBaseTotalOfflineRefunded(float $value)
* @method float getBaseTotalOnlineRefunded()
* @method Mage_Sales_Model_Order setBaseTotalOnlineRefunded(float $value)
* @method float getBaseTotalPaid()
* @method Mage_Sales_Model_Order setBaseTotalPaid(float $value)
* @method float getBaseTotalQtyOrdered()
* @method Mage_Sales_Model_Order setBaseTotalQtyOrdered(float $value)
* @method float getBaseTotalRefunded()
* @method Mage_Sales_Model_Order setBaseTotalRefunded(float $value)
* @method float getDiscountAmount()
* @method Mage_Sales_Model_Order setDiscountAmount(float $value)
* @method float getDiscountCanceled()
* @method Mage_Sales_Model_Order setDiscountCanceled(float $value)
* @method float getDiscountInvoiced()
* @method Mage_Sales_Model_Order setDiscountInvoiced(float $value)
* @method float getDiscountRefunded()
* @method Mage_Sales_Model_Order setDiscountRefunded(float $value)
* @method float getGrandTotal()
* @method Mage_Sales_Model_Order setGrandTotal(float $value)
* @method float getShippingAmount()
* @method Mage_Sales_Model_Order setShippingAmount(float $value)
* @method float getShippingCanceled()
* @method Mage_Sales_Model_Order setShippingCanceled(float $value)
* @method float getShippingInvoiced()
* @method Mage_Sales_Model_Order setShippingInvoiced(float $value)
* @method float getShippingRefunded()
* @method Mage_Sales_Model_Order setShippingRefunded(float $value)
* @method float getShippingTaxAmount()
* @method Mage_Sales_Model_Order setShippingTaxAmount(float $value)
* @method float getShippingTaxRefunded()
* @method Mage_Sales_Model_Order setShippingTaxRefunded(float $value)
* @method float getStoreToBaseRate()
* @method Mage_Sales_Model_Order setStoreToBaseRate(float $value)
* @method float getStoreToOrderRate()
* @method Mage_Sales_Model_Order setStoreToOrderRate(float $value)
* @method float getSubtotal()
* @method Mage_Sales_Model_Order setSubtotal(float $value)
* @method float getSubtotalCanceled()
* @method Mage_Sales_Model_Order setSubtotalCanceled(float $value)
* @method float getSubtotalInvoiced()
* @method Mage_Sales_Model_Order setSubtotalInvoiced(float $value)
* @method float getSubtotalRefunded()
* @method Mage_Sales_Model_Order setSubtotalRefunded(float $value)
* @method float getTaxAmount()
* @method Mage_Sales_Model_Order setTaxAmount(float $value)
* @method float getTaxCanceled()
* @method Mage_Sales_Model_Order setTaxCanceled(float $value)
* @method float getTaxInvoiced()
* @method Mage_Sales_Model_Order setTaxInvoiced(float $value)
* @method float getTaxRefunded()
* @method Mage_Sales_Model_Order setTaxRefunded(float $value)
* @method float getTotalCanceled()
* @method Mage_Sales_Model_Order setTotalCanceled(float $value)
* @method float getTotalInvoiced()
* @method Mage_Sales_Model_Order setTotalInvoiced(float $value)
* @method float getTotalOfflineRefunded()
* @method Mage_Sales_Model_Order setTotalOfflineRefunded(float $value)
* @method float getTotalOnlineRefunded()
* @method Mage_Sales_Model_Order setTotalOnlineRefunded(float $value)
* @method float getTotalPaid()
* @method Mage_Sales_Model_Order setTotalPaid(float $value)
* @method float getTotalQtyOrdered()
* @method Mage_Sales_Model_Order setTotalQtyOrdered(float $value)
* @method float getTotalRefunded()
* @method Mage_Sales_Model_Order setTotalRefunded(float $value)
* @method int getCanShipPartially()
* @method Mage_Sales_Model_Order setCanShipPartially(int $value)
* @method int getCanShipPartiallyItem()
* @method Mage_Sales_Model_Order setCanShipPartiallyItem(int $value)
* @method int getCustomerIsGuest()
* @method Mage_Sales_Model_Order setCustomerIsGuest(int $value)
* @method int getCustomerNoteNotify()
* @method Mage_Sales_Model_Order setCustomerNoteNotify(int $value)
* @method int getBillingAddressId()
* @method Mage_Sales_Model_Order setBillingAddressId(int $value)
* @method int getCustomerGroupId()
* @method Mage_Sales_Model_Order setCustomerGroupId(int $value)
* @method int getEditIncrement()
* @method Mage_Sales_Model_Order setEditIncrement(int $value)
* @method int getEmailSent()
* @method Mage_Sales_Model_Order setEmailSent(int $value)
* @method int getForcedDoShipmentWithInvoice()
* @method Mage_Sales_Model_Order setForcedDoShipmentWithInvoice(int $value)
* @method int getGiftMessageId()
* @method Mage_Sales_Model_Order setGiftMessageId(int $value)
* @method int getPaymentAuthorizationExpiration()
* @method Mage_Sales_Model_Order setPaymentAuthorizationExpiration(int $value)
* @method int getPaypalIpnCustomerNotified()
* @method Mage_Sales_Model_Order setPaypalIpnCustomerNotified(int $value)
* @method int getQuoteAddressId()
* @method Mage_Sales_Model_Order setQuoteAddressId(int $value)
* @method int getQuoteId()
* @method Mage_Sales_Model_Order setQuoteId(int $value)
* @method int getShippingAddressId()
* @method Mage_Sales_Model_Order setShippingAddressId(int $value)
* @method float getAdjustmentNegative()
* @method Mage_Sales_Model_Order setAdjustmentNegative(float $value)
* @method float getAdjustmentPositive()
* @method Mage_Sales_Model_Order setAdjustmentPositive(float $value)
* @method float getBaseAdjustmentNegative()
* @method Mage_Sales_Model_Order setBaseAdjustmentNegative(float $value)
* @method float getBaseAdjustmentPositive()
* @method Mage_Sales_Model_Order setBaseAdjustmentPositive(float $value)
* @method float getBaseShippingDiscountAmount()
* @method Mage_Sales_Model_Order setBaseShippingDiscountAmount(float $value)
* @method float getBaseSubtotalInclTax()
* @method Mage_Sales_Model_Order setBaseSubtotalInclTax(float $value)
* @method Mage_Sales_Model_Order setBaseTotalDue(float $value)
* @method float getPaymentAuthorizationAmount()
* @method Mage_Sales_Model_Order setPaymentAuthorizationAmount(float $value)
* @method float getShippingDiscountAmount()
* @method Mage_Sales_Model_Order setShippingDiscountAmount(float $value)
* @method float getSubtotalInclTax()
* @method Mage_Sales_Model_Order setSubtotalInclTax(float $value)
* @method Mage_Sales_Model_Order setTotalDue(float $value)
* @method float getWeight()
* @method Mage_Sales_Model_Order setWeight(float $value)
* @method string getCustomerDob()
* @method Mage_Sales_Model_Order setCustomerDob(string $value)
* @method string getIncrementId()
* @method Mage_Sales_Model_Order setIncrementId(string $value)
* @method string getAppliedRuleIds()
* @method Mage_Sales_Model_Order setAppliedRuleIds(string $value)
* @method string getBaseCurrencyCode()
* @method Mage_Sales_Model_Order setBaseCurrencyCode(string $value)
* @method string getCustomerEmail()
* @method Mage_Sales_Model_Order setCustomerEmail(string $value)
* @method string getCustomerFirstname()
* @method Mage_Sales_Model_Order setCustomerFirstname(string $value)
* @method string getCustomerLastname()
* @method Mage_Sales_Model_Order setCustomerLastname(string $value)
* @method string getCustomerMiddlename()
* @method Mage_Sales_Model_Order setCustomerMiddlename(string $value)
* @method string getCustomerPrefix()
* @method Mage_Sales_Model_Order setCustomerPrefix(string $value)
* @method string getCustomerSuffix()
* @method Mage_Sales_Model_Order setCustomerSuffix(string $value)
* @method string getCustomerTaxvat()
* @method Mage_Sales_Model_Order setCustomerTaxvat(string $value)
* @method string getDiscountDescription()
* @method Mage_Sales_Model_Order setDiscountDescription(string $value)
* @method string getExtCustomerId()
* @method Mage_Sales_Model_Order setExtCustomerId(string $value)
* @method string getExtOrderId()
* @method Mage_Sales_Model_Order setExtOrderId(string $value)
* @method string getGlobalCurrencyCode()
* @method Mage_Sales_Model_Order setGlobalCurrencyCode(string $value)
* @method string getHoldBeforeState()
* @method Mage_Sales_Model_Order setHoldBeforeState(string $value)
* @method string getHoldBeforeStatus()
* @method Mage_Sales_Model_Order setHoldBeforeStatus(string $value)
* @method string getOrderCurrencyCode()
* @method Mage_Sales_Model_Order setOrderCurrencyCode(string $value)
* @method string getOriginalIncrementId()
* @method Mage_Sales_Model_Order setOriginalIncrementId(string $value)
* @method string getRelationChildId()
* @method Mage_Sales_Model_Order setRelationChildId(string $value)
* @method string getRelationChildRealId()
* @method Mage_Sales_Model_Order setRelationChildRealId(string $value)
* @method string getRelationParentId()
* @method Mage_Sales_Model_Order setRelationParentId(string $value)
* @method string getRelationParentRealId()
* @method Mage_Sales_Model_Order setRelationParentRealId(string $value)
* @method string getRemoteIp()
* @method Mage_Sales_Model_Order setRemoteIp(string $value)
* @method Mage_Sales_Model_Order setShippingMethod(string $value)
* @method string getStoreCurrencyCode()
* @method Mage_Sales_Model_Order setStoreCurrencyCode(string $value)
* @method string getStoreName()
* @method Mage_Sales_Model_Order setStoreName(string $value)
* @method string getXForwardedFor()
* @method Mage_Sales_Model_Order setXForwardedFor(string $value)
* @method string getCustomerNote()
* @method Mage_Sales_Model_Order setCustomerNote(string $value)
* @method string getCreatedAt()
* @method Mage_Sales_Model_Order setCreatedAt(string $value)
* @method string getUpdatedAt()
* @method Mage_Sales_Model_Order setUpdatedAt(string $value)
* @method int getTotalItemCount()
* @method Mage_Sales_Model_Order setTotalItemCount(int $value)
* @method int getCustomerGender()
* @method Mage_Sales_Model_Order setCustomerGender(int $value)
* @method float getHiddenTaxAmount()
* @method Mage_Sales_Model_Order setHiddenTaxAmount(float $value)
* @method float getBaseHiddenTaxAmount()
* @method Mage_Sales_Model_Order setBaseHiddenTaxAmount(float $value)
* @method float getShippingHiddenTaxAmount()
* @method Mage_Sales_Model_Order setShippingHiddenTaxAmount(float $value)
* @method float getBaseShippingHiddenTaxAmount()
* @method Mage_Sales_Model_Order setBaseShippingHiddenTaxAmount(float $value)
* @method float getHiddenTaxInvoiced()
* @method Mage_Sales_Model_Order setHiddenTaxInvoiced(float $value)
* @method float getBaseHiddenTaxInvoiced()
* @method Mage_Sales_Model_Order setBaseHiddenTaxInvoiced(float $value)
* @method float getHiddenTaxRefunded()
* @method Mage_Sales_Model_Order setHiddenTaxRefunded(float $value)
* @method float getBaseHiddenTaxRefunded()
* @method Mage_Sales_Model_Order setBaseHiddenTaxRefunded(float $value)
* @method float getShippingInclTax()
* @method Mage_Sales_Model_Order setShippingInclTax(float $value)
* @method float getBaseShippingInclTax()
* @method Mage_Sales_Model_Order setBaseShippingInclTax(float $value)
*
* @category Mage
* @package Mage_Sales
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Sales_Model_Order extends Mage_Sales_Model_Abstract
{
/**
* Identifier for history item
*/
const ENTITY = 'order';
/**
* Event type names for order emails
*/
const EMAIL_EVENT_NAME_NEW_ORDER = 'new_order';
const EMAIL_EVENT_NAME_UPDATE_ORDER = 'update_order';
/**
* XML configuration paths
*/
const XML_PATH_EMAIL_TEMPLATE = 'sales_email/order/template';
const XML_PATH_EMAIL_GUEST_TEMPLATE = 'sales_email/order/guest_template';
const XML_PATH_EMAIL_IDENTITY = 'sales_email/order/identity';
const XML_PATH_EMAIL_COPY_TO = 'sales_email/order/copy_to';
const XML_PATH_EMAIL_COPY_METHOD = 'sales_email/order/copy_method';
const XML_PATH_EMAIL_ENABLED = 'sales_email/order/enabled';
const XML_PATH_UPDATE_EMAIL_TEMPLATE = 'sales_email/order_comment/template';
const XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE = 'sales_email/order_comment/guest_template';
const XML_PATH_UPDATE_EMAIL_IDENTITY = 'sales_email/order_comment/identity';
const XML_PATH_UPDATE_EMAIL_COPY_TO = 'sales_email/order_comment/copy_to';
const XML_PATH_UPDATE_EMAIL_COPY_METHOD = 'sales_email/order_comment/copy_method';
const XML_PATH_UPDATE_EMAIL_ENABLED = 'sales_email/order_comment/enabled';
/**
* Order states
*/
const STATE_NEW = 'new';
const STATE_PENDING_PAYMENT = 'pending_payment';
const STATE_PROCESSING = 'processing';
const STATE_COMPLETE = 'complete';
const STATE_CLOSED = 'closed';
const STATE_CANCELED = 'canceled';
const STATE_HOLDED = 'holded';
const STATE_PAYMENT_REVIEW = 'payment_review';
/**
* Order statuses
*/
const STATUS_FRAUD = 'fraud';
/**
* Order flags
*/
const ACTION_FLAG_CANCEL = 'cancel';
const ACTION_FLAG_HOLD = 'hold';
const ACTION_FLAG_UNHOLD = 'unhold';
const ACTION_FLAG_EDIT = 'edit';
const ACTION_FLAG_CREDITMEMO = 'creditmemo';
const ACTION_FLAG_INVOICE = 'invoice';
const ACTION_FLAG_REORDER = 'reorder';
const ACTION_FLAG_SHIP = 'ship';
const ACTION_FLAG_COMMENT = 'comment';
const ACTION_FLAG_PRODUCTS_PERMISSION_DENIED= 'product_permission_denied';
/**
* Report date types
*/
const REPORT_DATE_TYPE_CREATED = 'created';
const REPORT_DATE_TYPE_UPDATED = 'updated';
/*
* Identifier for history item
*/
const HISTORY_ENTITY_NAME = 'order';
protected $_eventPrefix = 'sales_order';
protected $_eventObject = 'order';
protected $_addresses = null;
protected $_items = null;
protected $_payments = null;
protected $_statusHistory = null;
protected $_invoices;
protected $_tracks;
protected $_shipments;
protected $_creditmemos;
protected $_relatedObjects = array();
protected $_orderCurrency = null;
protected $_baseCurrency = null;
/**
* Array of action flags for canUnhold, canEdit, etc.
*
* @var array
*/
protected $_actionFlag = array();
/**
* Flag: if after order placing we can send new email to the customer.
*
* @var bool
*/
protected $_canSendNewEmailFlag = true;
/*
* Identifier for history item
*
* @var string
*/
protected $_historyEntityName = self::HISTORY_ENTITY_NAME;
/**
* Initialize resource model
*/
protected function _construct()
{
$this->_init('sales/order');
}
/**
* Init mapping array of short fields to
* its full names
*
* @return Varien_Object
*/
protected function _initOldFieldsMap()
{
$this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order');
return $this;
}
/**
* Clear order object data
*
* @param string $key data key
* @return Mage_Sales_Model_Order
*/
public function unsetData($key=null)
{
parent::unsetData($key);
if (is_null($key)) {
$this->_items = null;
}
return $this;
}
/**
* Retrieve can flag for action (edit, unhold, etc..)
*
* @param string $action
* @return boolean|null
*/
public function getActionFlag($action)
{
if (isset($this->_actionFlag[$action])) {
return $this->_actionFlag[$action];
}
return null;
}
/**
* Set can flag value for action (edit, unhold, etc...)
*
* @param string $action
* @param boolean $flag
* @return Mage_Sales_Model_Order
*/
public function setActionFlag($action, $flag)
{
$this->_actionFlag[$action] = (boolean) $flag;
return $this;
}
/**
* Return flag for order if it can sends new email to customer.
*
* @return bool
*/
public function getCanSendNewEmailFlag()
{
return $this->_canSendNewEmailFlag;
}
/**
* Set flag for order if it can sends new email to customer.
*
* @param bool $flag
* @return Mage_Sales_Model_Order
*/
public function setCanSendNewEmailFlag($flag)
{
$this->_canSendNewEmailFlag = (boolean) $flag;
return $this;
}
/**
* Load order by system increment identifier
*
* @param string $incrementId
* @return Mage_Sales_Model_Order
*/
public function loadByIncrementId($incrementId)
{
return $this->loadByAttribute('increment_id', $incrementId);
}
/**
* Load order by custom attribute value. Attribute value should be unique
*
* @param string $attribute
* @param string $value
* @return Mage_Sales_Model_Order
*/
public function loadByAttribute($attribute, $value)
{
$this->load($value, $attribute);
return $this;
}
/**
* Retrieve store model instance
*
* @return Mage_Core_Model_Store
*/
public function getStore()
{
$storeId = $this->getStoreId();
if ($storeId) {
return Mage::app()->getStore($storeId);
}
return Mage::app()->getStore();
}
/**
* Retrieve order cancel availability
*
* @return bool
*/
public function canCancel()
{
if (!$this->_canVoidOrder()) {
return false;
}
if ($this->canUnhold()) { // $this->isPaymentReview()
return false;
}
$allInvoiced = true;
foreach ($this->getAllItems() as $item) {
if ($item->getQtyToInvoice()) {
$allInvoiced = false;
break;
}
}
if ($allInvoiced) {
return false;
}
$state = $this->getState();
if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
return false;
}
if ($this->getActionFlag(self::ACTION_FLAG_CANCEL) === false) {
return false;
}
/**
* Use only state for availability detect
*/
/*foreach ($this->getAllItems() as $item) {
if ($item->getQtyToCancel()>0) {
return true;
}
}
return false;*/
return true;
}
/**
* Getter whether the payment can be voided
*
* @return bool
*/
public function canVoidPayment()
{
return $this->_canVoidOrder() ? $this->getPayment()->canVoid($this->getPayment()) : false;
}
/**
* Check whether order could be canceled by states and flags
*
* @return bool
*/
protected function _canVoidOrder()
{
if ($this->canUnhold() || $this->isPaymentReview()) {
return false;
}
return true;
}
/**
* Retrieve order invoice availability
*
* @return bool
*/
public function canInvoice()
{
if ($this->canUnhold() || $this->isPaymentReview()) {
return false;
}
$state = $this->getState();
if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
return false;
}
if ($this->getActionFlag(self::ACTION_FLAG_INVOICE) === false) {
return false;
}
foreach ($this->getAllItems() as $item) {
if ($item->getQtyToInvoice()>0 && !$item->getLockedDoInvoice()) {
return true;
}
}
return false;
}
/**
* Retrieve order credit memo (refund) availability
*
* @return bool
*/
public function canCreditmemo()
{
if ($this->hasForcedCanCreditmemo()) {
return $this->getForcedCanCreditmemo();
}
if ($this->canUnhold() || $this->isPaymentReview()) {
return false;
}
if ($this->isCanceled() || $this->getState() === self::STATE_CLOSED) {
return false;
}
/**
* We can have problem with float in php (on some server $a=762.73;$b=762.73; $a-$b!=0)
* for this we have additional diapason for 0
* TotalPaid - contains amount, that were not rounded.
*/
if (abs($this->getStore()->roundPrice($this->getTotalPaid()) - $this->getTotalRefunded()) < .0001) {
return false;
}
if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) {
return false;
}
return true;
}
/**
* Retrieve order hold availability
*
* @return bool
*/
public function canHold()
{
$state = $this->getState();
if ($this->isCanceled() || $this->isPaymentReview()
|| $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED || $state === self::STATE_HOLDED) {
return false;
}
if ($this->getActionFlag(self::ACTION_FLAG_HOLD) === false) {
return false;
}
return true;
}
/**
* Retrieve order unhold availability
*
* @return bool
*/
public function canUnhold()
{
if ($this->getActionFlag(self::ACTION_FLAG_UNHOLD) === false || $this->isPaymentReview()) {
return false;
}
return $this->getState() === self::STATE_HOLDED;
}
/**
* Check if comment can be added to order history
*
* @return bool
*/
public function canComment()
{
if ($this->getActionFlag(self::ACTION_FLAG_COMMENT) === false) {
return false;
}
return true;
}
/**
* Retrieve order shipment availability
*
* @return bool
*/
public function canShip()
{
if ($this->canUnhold() || $this->isPaymentReview()) {
return false;
}
if ($this->getIsVirtual() || $this->isCanceled()) {
return false;
}
if ($this->getActionFlag(self::ACTION_FLAG_SHIP) === false) {
return false;
}
foreach ($this->getAllItems() as $item) {
if ($item->getQtyToShip()>0 && !$item->getIsVirtual()
&& !$item->getLockedDoShip())
{
return true;
}
}
return false;
}
/**
* Retrieve order edit availability
*
* @return bool
*/
public function canEdit()
{
if ($this->canUnhold()) {
return false;
}
$state = $this->getState();
if ($this->isCanceled() || $this->isPaymentReview()
|| $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
return false;
}
if (!$this->getPayment()->getMethodInstance()->canEdit()) {
return false;
}
if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) {
return false;
}
return true;
}
/**
* Retrieve order reorder availability
*
* @return bool
*/
public function canReorder()
{
return $this->_canReorder(false);
}
/**
* Check the ability to reorder ignoring the availability in stock or status of the ordered products
*
* @return bool
*/
public function canReorderIgnoreSalable()
{
return $this->_canReorder(true);
}
/**
* Retrieve order reorder availability
*
* @param bool $ignoreSalable
* @return bool
*/
protected function _canReorder($ignoreSalable = false)
{
if ($this->canUnhold() || $this->isPaymentReview() || !$this->getCustomerId()) {
return false;
}
if ($this->getActionFlag(self::ACTION_FLAG_REORDER) === false) {
return false;
}
$products = array();
foreach ($this->getItemsCollection() as $item) {
$products[] = $item->getProductId();
}
if (!empty($products)) {
/*
* @TODO ACPAOC: Use product collection here, but ensure that product
* is loaded with order store id, otherwise there'll be problems with isSalable()
* for configurables, bundles and other composites
*
*/
/*
$productsCollection = Mage::getModel('catalog/product')->getCollection()
->setStoreId($this->getStoreId())
->addIdFilter($products)
->addAttributeToSelect('status')
->load();
foreach ($productsCollection as $product) {
if (!$product->isSalable()) {
return false;
}
}
*/
foreach ($products as $productId) {
$product = Mage::getModel('catalog/product')
->setStoreId($this->getStoreId())
->load($productId);
}
if (!$product->getId() || (!$ignoreSalable && !$product->isSalable())) {
return false;
}
}
return true;
}
/**
* Check whether the payment is in payment review state
* In this state order cannot be normally processed. Possible actions can be:
* - accept or deny payment
* - fetch transaction information
*
* @return bool
*/
public function isPaymentReview()
{
return $this->getState() === self::STATE_PAYMENT_REVIEW;
}
/**
* Check whether payment can be accepted or denied
*
* @return bool
*/
public function canReviewPayment()
{
return $this->isPaymentReview() && $this->getPayment()->canReviewPayment();
}
/**
* Check whether there can be a transaction update fetched for payment in review state
*
* @return bool
*/
public function canFetchPaymentReviewUpdate()
{
return $this->isPaymentReview() && $this->getPayment()->canFetchTransactionInfo();
}
/**
* Retrieve order configuration model
*
* @return Mage_Sales_Model_Order_Config
*/
public function getConfig()
{
return Mage::getSingleton('sales/order_config');
}
/**
* Place order payments
*
* @return Mage_Sales_Model_Order
*/
protected function _placePayment()
{
$this->getPayment()->place();
return $this;
}
/**
* Retrieve order payment model object
*
* @return Mage_Sales_Model_Order_Payment
*/
public function getPayment()
{
foreach ($this->getPaymentsCollection() as $payment) {
if (!$payment->isDeleted()) {
return $payment;
}
}
return false;
}
/**
* Declare order billing address
*
* @param Mage_Sales_Model_Order_Address $address
* @return Mage_Sales_Model_Order
*/
public function setBillingAddress(Mage_Sales_Model_Order_Address $address)
{
$old = $this->getBillingAddress();
if (!empty($old)) {
$address->setId($old->getId());
}
$this->addAddress($address->setAddressType('billing'));
return $this;
}
/**
* Declare order shipping address
*
* @param Mage_Sales_Model_Order_Address $address
* @return Mage_Sales_Model_Order
*/
public function setShippingAddress(Mage_Sales_Model_Order_Address $address)
{
$old = $this->getShippingAddress();
if (!empty($old)) {
$address->setId($old->getId());
}
$this->addAddress($address->setAddressType('shipping'));
return $this;
}
/**
* Retrieve order billing address
*
* @return Mage_Sales_Model_Order_Address
*/
public function getBillingAddress()
{
foreach ($this->getAddressesCollection() as $address) {
if ($address->getAddressType()=='billing' && !$address->isDeleted()) {
return $address;
}
}
return false;
}
/**
* Retrieve order shipping address
*
* @return Mage_Sales_Model_Order_Address
*/
public function getShippingAddress()
{
foreach ($this->getAddressesCollection() as $address) {
if ($address->getAddressType()=='shipping' && !$address->isDeleted()) {
return $address;
}
}
return false;
}
/**
* Order state setter.
* If status is specified, will add order status history with specified comment
* the setData() cannot be overriden because of compatibility issues with resource model
*
* @param string $state
* @param string|bool $status
* @param string $comment
* @param bool $isCustomerNotified
* @return Mage_Sales_Model_Order
*/
public function setState($state, $status = false, $comment = '', $isCustomerNotified = null)
{
return $this->_setState($state, $status, $comment, $isCustomerNotified, true);
}
/**
* Order state protected setter.
* By default allows to set any state. Can also update status to default or specified value
* Сomplete and closed states are encapsulated intentionally, see the _checkState()