1: <?php
2:
3: namespace Thelia\Model\om;
4:
5: use \BaseObject;
6: use \BasePeer;
7: use \Criteria;
8: use \DateTime;
9: use \Exception;
10: use \PDO;
11: use \Persistent;
12: use \Propel;
13: use \PropelCollection;
14: use \PropelDateTime;
15: use \PropelException;
16: use \PropelObjectCollection;
17: use \PropelPDO;
18: use Thelia\Model\CouponOrder;
19: use Thelia\Model\CouponOrderQuery;
20: use Thelia\Model\Currency;
21: use Thelia\Model\CurrencyQuery;
22: use Thelia\Model\Customer;
23: use Thelia\Model\CustomerQuery;
24: use Thelia\Model\Order;
25: use Thelia\Model\OrderAddress;
26: use Thelia\Model\OrderAddressQuery;
27: use Thelia\Model\OrderPeer;
28: use Thelia\Model\OrderProduct;
29: use Thelia\Model\OrderProductQuery;
30: use Thelia\Model\OrderQuery;
31: use Thelia\Model\OrderStatus;
32: use Thelia\Model\OrderStatusQuery;
33:
34: 35: 36: 37: 38: 39: 40:
41: abstract class BaseOrder extends BaseObject implements Persistent
42: {
43: 44: 45:
46: const PEER = 'Thelia\\Model\\OrderPeer';
47:
48: 49: 50: 51: 52: 53:
54: protected static $peer;
55:
56: 57: 58: 59:
60: protected $startCopy = false;
61:
62: 63: 64: 65:
66: protected $id;
67:
68: 69: 70: 71:
72: protected $ref;
73:
74: 75: 76: 77:
78: protected $customer_id;
79:
80: 81: 82: 83:
84: protected $address_invoice;
85:
86: 87: 88: 89:
90: protected $address_delivery;
91:
92: 93: 94: 95:
96: protected $invoice_date;
97:
98: 99: 100: 101:
102: protected $currency_id;
103:
104: 105: 106: 107:
108: protected $currency_rate;
109:
110: 111: 112: 113:
114: protected $transaction;
115:
116: 117: 118: 119:
120: protected $delivery_num;
121:
122: 123: 124: 125:
126: protected $invoice;
127:
128: 129: 130: 131:
132: protected $postage;
133:
134: 135: 136: 137:
138: protected $payment;
139:
140: 141: 142: 143:
144: protected $carrier;
145:
146: 147: 148: 149:
150: protected $status_id;
151:
152: 153: 154: 155:
156: protected $lang;
157:
158: 159: 160: 161:
162: protected $created_at;
163:
164: 165: 166: 167:
168: protected $updated_at;
169:
170: 171: 172:
173: protected $aCurrency;
174:
175: 176: 177:
178: protected $aCustomer;
179:
180: 181: 182:
183: protected $aOrderAddressRelatedByAddressInvoice;
184:
185: 186: 187:
188: protected $aOrderAddressRelatedByAddressDelivery;
189:
190: 191: 192:
193: protected $aOrderStatus;
194:
195: 196: 197:
198: protected $collOrderProducts;
199: protected $collOrderProductsPartial;
200:
201: 202: 203:
204: protected $collCouponOrders;
205: protected $collCouponOrdersPartial;
206:
207: 208: 209: 210: 211:
212: protected $alreadyInSave = false;
213:
214: 215: 216: 217: 218:
219: protected $alreadyInValidation = false;
220:
221: 222: 223: 224:
225: protected $orderProductsScheduledForDeletion = null;
226:
227: 228: 229: 230:
231: protected = null;
232:
233: 234: 235: 236: 237:
238: public function getId()
239: {
240: return $this->id;
241: }
242:
243: 244: 245: 246: 247:
248: public function getRef()
249: {
250: return $this->ref;
251: }
252:
253: 254: 255: 256: 257:
258: public function getCustomerId()
259: {
260: return $this->customer_id;
261: }
262:
263: 264: 265: 266: 267:
268: public function getAddressInvoice()
269: {
270: return $this->address_invoice;
271: }
272:
273: 274: 275: 276: 277:
278: public function getAddressDelivery()
279: {
280: return $this->address_delivery;
281: }
282:
283: 284: 285: 286: 287: 288: 289: 290: 291:
292: public function getInvoiceDate($format = '%x')
293: {
294: if ($this->invoice_date === null) {
295: return null;
296: }
297:
298: if ($this->invoice_date === '0000-00-00') {
299:
300:
301: return null;
302: } else {
303: try {
304: $dt = new DateTime($this->invoice_date);
305: } catch (Exception $x) {
306: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->invoice_date, true), $x);
307: }
308: }
309:
310: if ($format === null) {
311:
312: return $dt;
313: } elseif (strpos($format, '%') !== false) {
314: return strftime($format, $dt->format('U'));
315: } else {
316: return $dt->format($format);
317: }
318: }
319:
320: 321: 322: 323: 324:
325: public function getCurrencyId()
326: {
327: return $this->currency_id;
328: }
329:
330: 331: 332: 333: 334:
335: public function getCurrencyRate()
336: {
337: return $this->currency_rate;
338: }
339:
340: 341: 342: 343: 344:
345: public function getTransaction()
346: {
347: return $this->transaction;
348: }
349:
350: 351: 352: 353: 354:
355: public function getDeliveryNum()
356: {
357: return $this->delivery_num;
358: }
359:
360: 361: 362: 363: 364:
365: public function getInvoice()
366: {
367: return $this->invoice;
368: }
369:
370: 371: 372: 373: 374:
375: public function getPostage()
376: {
377: return $this->postage;
378: }
379:
380: 381: 382: 383: 384:
385: public function getPayment()
386: {
387: return $this->payment;
388: }
389:
390: 391: 392: 393: 394:
395: public function getCarrier()
396: {
397: return $this->carrier;
398: }
399:
400: 401: 402: 403: 404:
405: public function getStatusId()
406: {
407: return $this->status_id;
408: }
409:
410: 411: 412: 413: 414:
415: public function getLang()
416: {
417: return $this->lang;
418: }
419:
420: 421: 422: 423: 424: 425: 426: 427: 428:
429: public function getCreatedAt($format = 'Y-m-d H:i:s')
430: {
431: if ($this->created_at === null) {
432: return null;
433: }
434:
435: if ($this->created_at === '0000-00-00 00:00:00') {
436:
437:
438: return null;
439: } else {
440: try {
441: $dt = new DateTime($this->created_at);
442: } catch (Exception $x) {
443: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->created_at, true), $x);
444: }
445: }
446:
447: if ($format === null) {
448:
449: return $dt;
450: } elseif (strpos($format, '%') !== false) {
451: return strftime($format, $dt->format('U'));
452: } else {
453: return $dt->format($format);
454: }
455: }
456:
457: 458: 459: 460: 461: 462: 463: 464: 465:
466: public function getUpdatedAt($format = 'Y-m-d H:i:s')
467: {
468: if ($this->updated_at === null) {
469: return null;
470: }
471:
472: if ($this->updated_at === '0000-00-00 00:00:00') {
473:
474:
475: return null;
476: } else {
477: try {
478: $dt = new DateTime($this->updated_at);
479: } catch (Exception $x) {
480: throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->updated_at, true), $x);
481: }
482: }
483:
484: if ($format === null) {
485:
486: return $dt;
487: } elseif (strpos($format, '%') !== false) {
488: return strftime($format, $dt->format('U'));
489: } else {
490: return $dt->format($format);
491: }
492: }
493:
494: 495: 496: 497: 498: 499:
500: public function setId($v)
501: {
502: if ($v !== null) {
503: $v = (int) $v;
504: }
505:
506: if ($this->id !== $v) {
507: $this->id = $v;
508: $this->modifiedColumns[] = OrderPeer::ID;
509: }
510:
511:
512: return $this;
513: }
514:
515: 516: 517: 518: 519: 520:
521: public function setRef($v)
522: {
523: if ($v !== null) {
524: $v = (string) $v;
525: }
526:
527: if ($this->ref !== $v) {
528: $this->ref = $v;
529: $this->modifiedColumns[] = OrderPeer::REF;
530: }
531:
532:
533: return $this;
534: }
535:
536: 537: 538: 539: 540: 541:
542: public function setCustomerId($v)
543: {
544: if ($v !== null) {
545: $v = (int) $v;
546: }
547:
548: if ($this->customer_id !== $v) {
549: $this->customer_id = $v;
550: $this->modifiedColumns[] = OrderPeer::CUSTOMER_ID;
551: }
552:
553: if ($this->aCustomer !== null && $this->aCustomer->getId() !== $v) {
554: $this->aCustomer = null;
555: }
556:
557:
558: return $this;
559: }
560:
561: 562: 563: 564: 565: 566:
567: public function setAddressInvoice($v)
568: {
569: if ($v !== null) {
570: $v = (int) $v;
571: }
572:
573: if ($this->address_invoice !== $v) {
574: $this->address_invoice = $v;
575: $this->modifiedColumns[] = OrderPeer::ADDRESS_INVOICE;
576: }
577:
578: if ($this->aOrderAddressRelatedByAddressInvoice !== null && $this->aOrderAddressRelatedByAddressInvoice->getId() !== $v) {
579: $this->aOrderAddressRelatedByAddressInvoice = null;
580: }
581:
582:
583: return $this;
584: }
585:
586: 587: 588: 589: 590: 591:
592: public function setAddressDelivery($v)
593: {
594: if ($v !== null) {
595: $v = (int) $v;
596: }
597:
598: if ($this->address_delivery !== $v) {
599: $this->address_delivery = $v;
600: $this->modifiedColumns[] = OrderPeer::ADDRESS_DELIVERY;
601: }
602:
603: if ($this->aOrderAddressRelatedByAddressDelivery !== null && $this->aOrderAddressRelatedByAddressDelivery->getId() !== $v) {
604: $this->aOrderAddressRelatedByAddressDelivery = null;
605: }
606:
607:
608: return $this;
609: }
610:
611: 612: 613: 614: 615: 616: 617:
618: public function setInvoiceDate($v)
619: {
620: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
621: if ($this->invoice_date !== null || $dt !== null) {
622: $currentDateAsString = ($this->invoice_date !== null && $tmpDt = new DateTime($this->invoice_date)) ? $tmpDt->format('Y-m-d') : null;
623: $newDateAsString = $dt ? $dt->format('Y-m-d') : null;
624: if ($currentDateAsString !== $newDateAsString) {
625: $this->invoice_date = $newDateAsString;
626: $this->modifiedColumns[] = OrderPeer::INVOICE_DATE;
627: }
628: }
629:
630:
631: return $this;
632: }
633:
634: 635: 636: 637: 638: 639:
640: public function setCurrencyId($v)
641: {
642: if ($v !== null) {
643: $v = (int) $v;
644: }
645:
646: if ($this->currency_id !== $v) {
647: $this->currency_id = $v;
648: $this->modifiedColumns[] = OrderPeer::CURRENCY_ID;
649: }
650:
651: if ($this->aCurrency !== null && $this->aCurrency->getId() !== $v) {
652: $this->aCurrency = null;
653: }
654:
655:
656: return $this;
657: }
658:
659: 660: 661: 662: 663: 664:
665: public function setCurrencyRate($v)
666: {
667: if ($v !== null) {
668: $v = (double) $v;
669: }
670:
671: if ($this->currency_rate !== $v) {
672: $this->currency_rate = $v;
673: $this->modifiedColumns[] = OrderPeer::CURRENCY_RATE;
674: }
675:
676:
677: return $this;
678: }
679:
680: 681: 682: 683: 684: 685:
686: public function setTransaction($v)
687: {
688: if ($v !== null) {
689: $v = (string) $v;
690: }
691:
692: if ($this->transaction !== $v) {
693: $this->transaction = $v;
694: $this->modifiedColumns[] = OrderPeer::TRANSACTION;
695: }
696:
697:
698: return $this;
699: }
700:
701: 702: 703: 704: 705: 706:
707: public function setDeliveryNum($v)
708: {
709: if ($v !== null) {
710: $v = (string) $v;
711: }
712:
713: if ($this->delivery_num !== $v) {
714: $this->delivery_num = $v;
715: $this->modifiedColumns[] = OrderPeer::DELIVERY_NUM;
716: }
717:
718:
719: return $this;
720: }
721:
722: 723: 724: 725: 726: 727:
728: public function setInvoice($v)
729: {
730: if ($v !== null) {
731: $v = (string) $v;
732: }
733:
734: if ($this->invoice !== $v) {
735: $this->invoice = $v;
736: $this->modifiedColumns[] = OrderPeer::INVOICE;
737: }
738:
739:
740: return $this;
741: }
742:
743: 744: 745: 746: 747: 748:
749: public function setPostage($v)
750: {
751: if ($v !== null) {
752: $v = (double) $v;
753: }
754:
755: if ($this->postage !== $v) {
756: $this->postage = $v;
757: $this->modifiedColumns[] = OrderPeer::POSTAGE;
758: }
759:
760:
761: return $this;
762: }
763:
764: 765: 766: 767: 768: 769:
770: public function setPayment($v)
771: {
772: if ($v !== null) {
773: $v = (string) $v;
774: }
775:
776: if ($this->payment !== $v) {
777: $this->payment = $v;
778: $this->modifiedColumns[] = OrderPeer::PAYMENT;
779: }
780:
781:
782: return $this;
783: }
784:
785: 786: 787: 788: 789: 790:
791: public function setCarrier($v)
792: {
793: if ($v !== null) {
794: $v = (string) $v;
795: }
796:
797: if ($this->carrier !== $v) {
798: $this->carrier = $v;
799: $this->modifiedColumns[] = OrderPeer::CARRIER;
800: }
801:
802:
803: return $this;
804: }
805:
806: 807: 808: 809: 810: 811:
812: public function setStatusId($v)
813: {
814: if ($v !== null) {
815: $v = (int) $v;
816: }
817:
818: if ($this->status_id !== $v) {
819: $this->status_id = $v;
820: $this->modifiedColumns[] = OrderPeer::STATUS_ID;
821: }
822:
823: if ($this->aOrderStatus !== null && $this->aOrderStatus->getId() !== $v) {
824: $this->aOrderStatus = null;
825: }
826:
827:
828: return $this;
829: }
830:
831: 832: 833: 834: 835: 836:
837: public function setLang($v)
838: {
839: if ($v !== null) {
840: $v = (string) $v;
841: }
842:
843: if ($this->lang !== $v) {
844: $this->lang = $v;
845: $this->modifiedColumns[] = OrderPeer::LANG;
846: }
847:
848:
849: return $this;
850: }
851:
852: 853: 854: 855: 856: 857: 858:
859: public function setCreatedAt($v)
860: {
861: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
862: if ($this->created_at !== null || $dt !== null) {
863: $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
864: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
865: if ($currentDateAsString !== $newDateAsString) {
866: $this->created_at = $newDateAsString;
867: $this->modifiedColumns[] = OrderPeer::CREATED_AT;
868: }
869: }
870:
871:
872: return $this;
873: }
874:
875: 876: 877: 878: 879: 880: 881:
882: public function setUpdatedAt($v)
883: {
884: $dt = PropelDateTime::newInstance($v, null, 'DateTime');
885: if ($this->updated_at !== null || $dt !== null) {
886: $currentDateAsString = ($this->updated_at !== null && $tmpDt = new DateTime($this->updated_at)) ? $tmpDt->format('Y-m-d H:i:s') : null;
887: $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
888: if ($currentDateAsString !== $newDateAsString) {
889: $this->updated_at = $newDateAsString;
890: $this->modifiedColumns[] = OrderPeer::UPDATED_AT;
891: }
892: }
893:
894:
895: return $this;
896: }
897:
898: 899: 900: 901: 902: 903: 904: 905:
906: public function hasOnlyDefaultValues()
907: {
908:
909: return true;
910: }
911:
912: 913: 914: 915: 916: 917: 918: 919: 920: 921: 922: 923: 924: 925:
926: public function hydrate($row, $startcol = 0, $rehydrate = false)
927: {
928: try {
929:
930: $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
931: $this->ref = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
932: $this->customer_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
933: $this->address_invoice = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null;
934: $this->address_delivery = ($row[$startcol + 4] !== null) ? (int) $row[$startcol + 4] : null;
935: $this->invoice_date = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
936: $this->currency_id = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
937: $this->currency_rate = ($row[$startcol + 7] !== null) ? (double) $row[$startcol + 7] : null;
938: $this->transaction = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
939: $this->delivery_num = ($row[$startcol + 9] !== null) ? (string) $row[$startcol + 9] : null;
940: $this->invoice = ($row[$startcol + 10] !== null) ? (string) $row[$startcol + 10] : null;
941: $this->postage = ($row[$startcol + 11] !== null) ? (double) $row[$startcol + 11] : null;
942: $this->payment = ($row[$startcol + 12] !== null) ? (string) $row[$startcol + 12] : null;
943: $this->carrier = ($row[$startcol + 13] !== null) ? (string) $row[$startcol + 13] : null;
944: $this->status_id = ($row[$startcol + 14] !== null) ? (int) $row[$startcol + 14] : null;
945: $this->lang = ($row[$startcol + 15] !== null) ? (string) $row[$startcol + 15] : null;
946: $this->created_at = ($row[$startcol + 16] !== null) ? (string) $row[$startcol + 16] : null;
947: $this->updated_at = ($row[$startcol + 17] !== null) ? (string) $row[$startcol + 17] : null;
948: $this->resetModified();
949:
950: $this->setNew(false);
951:
952: if ($rehydrate) {
953: $this->ensureConsistency();
954: }
955:
956: return $startcol + 18;
957:
958: } catch (Exception $e) {
959: throw new PropelException("Error populating Order object", $e);
960: }
961: }
962:
963: 964: 965: 966: 967: 968: 969: 970: 971: 972: 973: 974: 975:
976: public function ensureConsistency()
977: {
978:
979: if ($this->aCustomer !== null && $this->customer_id !== $this->aCustomer->getId()) {
980: $this->aCustomer = null;
981: }
982: if ($this->aOrderAddressRelatedByAddressInvoice !== null && $this->address_invoice !== $this->aOrderAddressRelatedByAddressInvoice->getId()) {
983: $this->aOrderAddressRelatedByAddressInvoice = null;
984: }
985: if ($this->aOrderAddressRelatedByAddressDelivery !== null && $this->address_delivery !== $this->aOrderAddressRelatedByAddressDelivery->getId()) {
986: $this->aOrderAddressRelatedByAddressDelivery = null;
987: }
988: if ($this->aCurrency !== null && $this->currency_id !== $this->aCurrency->getId()) {
989: $this->aCurrency = null;
990: }
991: if ($this->aOrderStatus !== null && $this->status_id !== $this->aOrderStatus->getId()) {
992: $this->aOrderStatus = null;
993: }
994: }
995:
996: 997: 998: 999: 1000: 1001: 1002: 1003: 1004: 1005:
1006: public function reload($deep = false, PropelPDO $con = null)
1007: {
1008: if ($this->isDeleted()) {
1009: throw new PropelException("Cannot reload a deleted object.");
1010: }
1011:
1012: if ($this->isNew()) {
1013: throw new PropelException("Cannot reload an unsaved object.");
1014: }
1015:
1016: if ($con === null) {
1017: $con = Propel::getConnection(OrderPeer::DATABASE_NAME, Propel::CONNECTION_READ);
1018: }
1019:
1020:
1021:
1022:
1023: $stmt = OrderPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
1024: $row = $stmt->fetch(PDO::FETCH_NUM);
1025: $stmt->closeCursor();
1026: if (!$row) {
1027: throw new PropelException('Cannot find matching row in the database to reload object values.');
1028: }
1029: $this->hydrate($row, 0, true);
1030:
1031: if ($deep) {
1032:
1033: $this->aCurrency = null;
1034: $this->aCustomer = null;
1035: $this->aOrderAddressRelatedByAddressInvoice = null;
1036: $this->aOrderAddressRelatedByAddressDelivery = null;
1037: $this->aOrderStatus = null;
1038: $this->collOrderProducts = null;
1039:
1040: $this->collCouponOrders = null;
1041:
1042: }
1043: }
1044:
1045: 1046: 1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054:
1055: public function delete(PropelPDO $con = null)
1056: {
1057: if ($this->isDeleted()) {
1058: throw new PropelException("This object has already been deleted.");
1059: }
1060:
1061: if ($con === null) {
1062: $con = Propel::getConnection(OrderPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
1063: }
1064:
1065: $con->beginTransaction();
1066: try {
1067: $deleteQuery = OrderQuery::create()
1068: ->filterByPrimaryKey($this->getPrimaryKey());
1069: $ret = $this->preDelete($con);
1070: if ($ret) {
1071: $deleteQuery->delete($con);
1072: $this->postDelete($con);
1073: $con->commit();
1074: $this->setDeleted(true);
1075: } else {
1076: $con->commit();
1077: }
1078: } catch (Exception $e) {
1079: $con->rollBack();
1080: throw $e;
1081: }
1082: }
1083:
1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097:
1098: public function save(PropelPDO $con = null)
1099: {
1100: if ($this->isDeleted()) {
1101: throw new PropelException("You cannot save an object that has been deleted.");
1102: }
1103:
1104: if ($con === null) {
1105: $con = Propel::getConnection(OrderPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
1106: }
1107:
1108: $con->beginTransaction();
1109: $isInsert = $this->isNew();
1110: try {
1111: $ret = $this->preSave($con);
1112: if ($isInsert) {
1113: $ret = $ret && $this->preInsert($con);
1114:
1115: if (!$this->isColumnModified(OrderPeer::CREATED_AT)) {
1116: $this->setCreatedAt(time());
1117: }
1118: if (!$this->isColumnModified(OrderPeer::UPDATED_AT)) {
1119: $this->setUpdatedAt(time());
1120: }
1121: } else {
1122: $ret = $ret && $this->preUpdate($con);
1123:
1124: if ($this->isModified() && !$this->isColumnModified(OrderPeer::UPDATED_AT)) {
1125: $this->setUpdatedAt(time());
1126: }
1127: }
1128: if ($ret) {
1129: $affectedRows = $this->doSave($con);
1130: if ($isInsert) {
1131: $this->postInsert($con);
1132: } else {
1133: $this->postUpdate($con);
1134: }
1135: $this->postSave($con);
1136: OrderPeer::addInstanceToPool($this);
1137: } else {
1138: $affectedRows = 0;
1139: }
1140: $con->commit();
1141:
1142: return $affectedRows;
1143: } catch (Exception $e) {
1144: $con->rollBack();
1145: throw $e;
1146: }
1147: }
1148:
1149: 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159:
1160: protected function doSave(PropelPDO $con)
1161: {
1162: $affectedRows = 0;
1163: if (!$this->alreadyInSave) {
1164: $this->alreadyInSave = true;
1165:
1166:
1167:
1168:
1169:
1170:
1171: if ($this->aCurrency !== null) {
1172: if ($this->aCurrency->isModified() || $this->aCurrency->isNew()) {
1173: $affectedRows += $this->aCurrency->save($con);
1174: }
1175: $this->setCurrency($this->aCurrency);
1176: }
1177:
1178: if ($this->aCustomer !== null) {
1179: if ($this->aCustomer->isModified() || $this->aCustomer->isNew()) {
1180: $affectedRows += $this->aCustomer->save($con);
1181: }
1182: $this->setCustomer($this->aCustomer);
1183: }
1184:
1185: if ($this->aOrderAddressRelatedByAddressInvoice !== null) {
1186: if ($this->aOrderAddressRelatedByAddressInvoice->isModified() || $this->aOrderAddressRelatedByAddressInvoice->isNew()) {
1187: $affectedRows += $this->aOrderAddressRelatedByAddressInvoice->save($con);
1188: }
1189: $this->setOrderAddressRelatedByAddressInvoice($this->aOrderAddressRelatedByAddressInvoice);
1190: }
1191:
1192: if ($this->aOrderAddressRelatedByAddressDelivery !== null) {
1193: if ($this->aOrderAddressRelatedByAddressDelivery->isModified() || $this->aOrderAddressRelatedByAddressDelivery->isNew()) {
1194: $affectedRows += $this->aOrderAddressRelatedByAddressDelivery->save($con);
1195: }
1196: $this->setOrderAddressRelatedByAddressDelivery($this->aOrderAddressRelatedByAddressDelivery);
1197: }
1198:
1199: if ($this->aOrderStatus !== null) {
1200: if ($this->aOrderStatus->isModified() || $this->aOrderStatus->isNew()) {
1201: $affectedRows += $this->aOrderStatus->save($con);
1202: }
1203: $this->setOrderStatus($this->aOrderStatus);
1204: }
1205:
1206: if ($this->isNew() || $this->isModified()) {
1207:
1208: if ($this->isNew()) {
1209: $this->doInsert($con);
1210: } else {
1211: $this->doUpdate($con);
1212: }
1213: $affectedRows += 1;
1214: $this->resetModified();
1215: }
1216:
1217: if ($this->orderProductsScheduledForDeletion !== null) {
1218: if (!$this->orderProductsScheduledForDeletion->isEmpty()) {
1219: OrderProductQuery::create()
1220: ->filterByPrimaryKeys($this->orderProductsScheduledForDeletion->getPrimaryKeys(false))
1221: ->delete($con);
1222: $this->orderProductsScheduledForDeletion = null;
1223: }
1224: }
1225:
1226: if ($this->collOrderProducts !== null) {
1227: foreach ($this->collOrderProducts as $referrerFK) {
1228: if (!$referrerFK->isDeleted()) {
1229: $affectedRows += $referrerFK->save($con);
1230: }
1231: }
1232: }
1233:
1234: if ($this->couponOrdersScheduledForDeletion !== null) {
1235: if (!$this->couponOrdersScheduledForDeletion->isEmpty()) {
1236: CouponOrderQuery::create()
1237: ->filterByPrimaryKeys($this->couponOrdersScheduledForDeletion->getPrimaryKeys(false))
1238: ->delete($con);
1239: $this->couponOrdersScheduledForDeletion = null;
1240: }
1241: }
1242:
1243: if ($this->collCouponOrders !== null) {
1244: foreach ($this->collCouponOrders as $referrerFK) {
1245: if (!$referrerFK->isDeleted()) {
1246: $affectedRows += $referrerFK->save($con);
1247: }
1248: }
1249: }
1250:
1251: $this->alreadyInSave = false;
1252:
1253: }
1254:
1255: return $affectedRows;
1256: }
1257:
1258: 1259: 1260: 1261: 1262: 1263: 1264: 1265:
1266: protected function doInsert(PropelPDO $con)
1267: {
1268: $modifiedColumns = array();
1269: $index = 0;
1270:
1271: $this->modifiedColumns[] = OrderPeer::ID;
1272: if (null !== $this->id) {
1273: throw new PropelException('Cannot insert a value for auto-increment primary key (' . OrderPeer::ID . ')');
1274: }
1275:
1276:
1277: if ($this->isColumnModified(OrderPeer::ID)) {
1278: $modifiedColumns[':p' . $index++] = '`ID`';
1279: }
1280: if ($this->isColumnModified(OrderPeer::REF)) {
1281: $modifiedColumns[':p' . $index++] = '`REF`';
1282: }
1283: if ($this->isColumnModified(OrderPeer::CUSTOMER_ID)) {
1284: $modifiedColumns[':p' . $index++] = '`CUSTOMER_ID`';
1285: }
1286: if ($this->isColumnModified(OrderPeer::ADDRESS_INVOICE)) {
1287: $modifiedColumns[':p' . $index++] = '`ADDRESS_INVOICE`';
1288: }
1289: if ($this->isColumnModified(OrderPeer::ADDRESS_DELIVERY)) {
1290: $modifiedColumns[':p' . $index++] = '`ADDRESS_DELIVERY`';
1291: }
1292: if ($this->isColumnModified(OrderPeer::INVOICE_DATE)) {
1293: $modifiedColumns[':p' . $index++] = '`INVOICE_DATE`';
1294: }
1295: if ($this->isColumnModified(OrderPeer::CURRENCY_ID)) {
1296: $modifiedColumns[':p' . $index++] = '`CURRENCY_ID`';
1297: }
1298: if ($this->isColumnModified(OrderPeer::CURRENCY_RATE)) {
1299: $modifiedColumns[':p' . $index++] = '`CURRENCY_RATE`';
1300: }
1301: if ($this->isColumnModified(OrderPeer::TRANSACTION)) {
1302: $modifiedColumns[':p' . $index++] = '`TRANSACTION`';
1303: }
1304: if ($this->isColumnModified(OrderPeer::DELIVERY_NUM)) {
1305: $modifiedColumns[':p' . $index++] = '`DELIVERY_NUM`';
1306: }
1307: if ($this->isColumnModified(OrderPeer::INVOICE)) {
1308: $modifiedColumns[':p' . $index++] = '`INVOICE`';
1309: }
1310: if ($this->isColumnModified(OrderPeer::POSTAGE)) {
1311: $modifiedColumns[':p' . $index++] = '`POSTAGE`';
1312: }
1313: if ($this->isColumnModified(OrderPeer::PAYMENT)) {
1314: $modifiedColumns[':p' . $index++] = '`PAYMENT`';
1315: }
1316: if ($this->isColumnModified(OrderPeer::CARRIER)) {
1317: $modifiedColumns[':p' . $index++] = '`CARRIER`';
1318: }
1319: if ($this->isColumnModified(OrderPeer::STATUS_ID)) {
1320: $modifiedColumns[':p' . $index++] = '`STATUS_ID`';
1321: }
1322: if ($this->isColumnModified(OrderPeer::LANG)) {
1323: $modifiedColumns[':p' . $index++] = '`LANG`';
1324: }
1325: if ($this->isColumnModified(OrderPeer::CREATED_AT)) {
1326: $modifiedColumns[':p' . $index++] = '`CREATED_AT`';
1327: }
1328: if ($this->isColumnModified(OrderPeer::UPDATED_AT)) {
1329: $modifiedColumns[':p' . $index++] = '`UPDATED_AT`';
1330: }
1331:
1332: $sql = sprintf(
1333: 'INSERT INTO `order` (%s) VALUES (%s)',
1334: implode(', ', $modifiedColumns),
1335: implode(', ', array_keys($modifiedColumns))
1336: );
1337:
1338: try {
1339: $stmt = $con->prepare($sql);
1340: foreach ($modifiedColumns as $identifier => $columnName) {
1341: switch ($columnName) {
1342: case '`ID`':
1343: $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
1344: break;
1345: case '`REF`':
1346: $stmt->bindValue($identifier, $this->ref, PDO::PARAM_STR);
1347: break;
1348: case '`CUSTOMER_ID`':
1349: $stmt->bindValue($identifier, $this->customer_id, PDO::PARAM_INT);
1350: break;
1351: case '`ADDRESS_INVOICE`':
1352: $stmt->bindValue($identifier, $this->address_invoice, PDO::PARAM_INT);
1353: break;
1354: case '`ADDRESS_DELIVERY`':
1355: $stmt->bindValue($identifier, $this->address_delivery, PDO::PARAM_INT);
1356: break;
1357: case '`INVOICE_DATE`':
1358: $stmt->bindValue($identifier, $this->invoice_date, PDO::PARAM_STR);
1359: break;
1360: case '`CURRENCY_ID`':
1361: $stmt->bindValue($identifier, $this->currency_id, PDO::PARAM_INT);
1362: break;
1363: case '`CURRENCY_RATE`':
1364: $stmt->bindValue($identifier, $this->currency_rate, PDO::PARAM_STR);
1365: break;
1366: case '`TRANSACTION`':
1367: $stmt->bindValue($identifier, $this->transaction, PDO::PARAM_STR);
1368: break;
1369: case '`DELIVERY_NUM`':
1370: $stmt->bindValue($identifier, $this->delivery_num, PDO::PARAM_STR);
1371: break;
1372: case '`INVOICE`':
1373: $stmt->bindValue($identifier, $this->invoice, PDO::PARAM_STR);
1374: break;
1375: case '`POSTAGE`':
1376: $stmt->bindValue($identifier, $this->postage, PDO::PARAM_STR);
1377: break;
1378: case '`PAYMENT`':
1379: $stmt->bindValue($identifier, $this->payment, PDO::PARAM_STR);
1380: break;
1381: case '`CARRIER`':
1382: $stmt->bindValue($identifier, $this->carrier, PDO::PARAM_STR);
1383: break;
1384: case '`STATUS_ID`':
1385: $stmt->bindValue($identifier, $this->status_id, PDO::PARAM_INT);
1386: break;
1387: case '`LANG`':
1388: $stmt->bindValue($identifier, $this->lang, PDO::PARAM_STR);
1389: break;
1390: case '`CREATED_AT`':
1391: $stmt->bindValue($identifier, $this->created_at, PDO::PARAM_STR);
1392: break;
1393: case '`UPDATED_AT`':
1394: $stmt->bindValue($identifier, $this->updated_at, PDO::PARAM_STR);
1395: break;
1396: }
1397: }
1398: $stmt->execute();
1399: } catch (Exception $e) {
1400: Propel::log($e->getMessage(), Propel::LOG_ERR);
1401: throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
1402: }
1403:
1404: try {
1405: $pk = $con->lastInsertId();
1406: } catch (Exception $e) {
1407: throw new PropelException('Unable to get autoincrement id.', $e);
1408: }
1409: $this->setId($pk);
1410:
1411: $this->setNew(false);
1412: }
1413:
1414: 1415: 1416: 1417: 1418: 1419: 1420:
1421: protected function doUpdate(PropelPDO $con)
1422: {
1423: $selectCriteria = $this->buildPkeyCriteria();
1424: $valuesCriteria = $this->buildCriteria();
1425: BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
1426: }
1427:
1428: 1429: 1430: 1431:
1432: protected $validationFailures = array();
1433:
1434: 1435: 1436: 1437: 1438: 1439: 1440:
1441: public function getValidationFailures()
1442: {
1443: return $this->validationFailures;
1444: }
1445:
1446: 1447: 1448: 1449: 1450: 1451: 1452: 1453: 1454: 1455: 1456:
1457: public function validate($columns = null)
1458: {
1459: $res = $this->doValidate($columns);
1460: if ($res === true) {
1461: $this->validationFailures = array();
1462:
1463: return true;
1464: } else {
1465: $this->validationFailures = $res;
1466:
1467: return false;
1468: }
1469: }
1470:
1471: 1472: 1473: 1474: 1475: 1476: 1477: 1478: 1479: 1480:
1481: protected function doValidate($columns = null)
1482: {
1483: if (!$this->alreadyInValidation) {
1484: $this->alreadyInValidation = true;
1485: $retval = null;
1486:
1487: $failureMap = array();
1488:
1489:
1490:
1491:
1492:
1493:
1494:
1495: if ($this->aCurrency !== null) {
1496: if (!$this->aCurrency->validate($columns)) {
1497: $failureMap = array_merge($failureMap, $this->aCurrency->getValidationFailures());
1498: }
1499: }
1500:
1501: if ($this->aCustomer !== null) {
1502: if (!$this->aCustomer->validate($columns)) {
1503: $failureMap = array_merge($failureMap, $this->aCustomer->getValidationFailures());
1504: }
1505: }
1506:
1507: if ($this->aOrderAddressRelatedByAddressInvoice !== null) {
1508: if (!$this->aOrderAddressRelatedByAddressInvoice->validate($columns)) {
1509: $failureMap = array_merge($failureMap, $this->aOrderAddressRelatedByAddressInvoice->getValidationFailures());
1510: }
1511: }
1512:
1513: if ($this->aOrderAddressRelatedByAddressDelivery !== null) {
1514: if (!$this->aOrderAddressRelatedByAddressDelivery->validate($columns)) {
1515: $failureMap = array_merge($failureMap, $this->aOrderAddressRelatedByAddressDelivery->getValidationFailures());
1516: }
1517: }
1518:
1519: if ($this->aOrderStatus !== null) {
1520: if (!$this->aOrderStatus->validate($columns)) {
1521: $failureMap = array_merge($failureMap, $this->aOrderStatus->getValidationFailures());
1522: }
1523: }
1524:
1525:
1526: if (($retval = OrderPeer::doValidate($this, $columns)) !== true) {
1527: $failureMap = array_merge($failureMap, $retval);
1528: }
1529:
1530:
1531: if ($this->collOrderProducts !== null) {
1532: foreach ($this->collOrderProducts as $referrerFK) {
1533: if (!$referrerFK->validate($columns)) {
1534: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
1535: }
1536: }
1537: }
1538:
1539: if ($this->collCouponOrders !== null) {
1540: foreach ($this->collCouponOrders as $referrerFK) {
1541: if (!$referrerFK->validate($columns)) {
1542: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
1543: }
1544: }
1545: }
1546:
1547:
1548: $this->alreadyInValidation = false;
1549: }
1550:
1551: return (!empty($failureMap) ? $failureMap : true);
1552: }
1553:
1554: 1555: 1556: 1557: 1558: 1559: 1560: 1561: 1562: 1563:
1564: public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
1565: {
1566: $pos = OrderPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
1567: $field = $this->getByPosition($pos);
1568:
1569: return $field;
1570: }
1571:
1572: 1573: 1574: 1575: 1576: 1577: 1578:
1579: public function getByPosition($pos)
1580: {
1581: switch ($pos) {
1582: case 0:
1583: return $this->getId();
1584: break;
1585: case 1:
1586: return $this->getRef();
1587: break;
1588: case 2:
1589: return $this->getCustomerId();
1590: break;
1591: case 3:
1592: return $this->getAddressInvoice();
1593: break;
1594: case 4:
1595: return $this->getAddressDelivery();
1596: break;
1597: case 5:
1598: return $this->getInvoiceDate();
1599: break;
1600: case 6:
1601: return $this->getCurrencyId();
1602: break;
1603: case 7:
1604: return $this->getCurrencyRate();
1605: break;
1606: case 8:
1607: return $this->getTransaction();
1608: break;
1609: case 9:
1610: return $this->getDeliveryNum();
1611: break;
1612: case 10:
1613: return $this->getInvoice();
1614: break;
1615: case 11:
1616: return $this->getPostage();
1617: break;
1618: case 12:
1619: return $this->getPayment();
1620: break;
1621: case 13:
1622: return $this->getCarrier();
1623: break;
1624: case 14:
1625: return $this->getStatusId();
1626: break;
1627: case 15:
1628: return $this->getLang();
1629: break;
1630: case 16:
1631: return $this->getCreatedAt();
1632: break;
1633: case 17:
1634: return $this->getUpdatedAt();
1635: break;
1636: default:
1637: return null;
1638: break;
1639: }
1640: }
1641:
1642: 1643: 1644: 1645: 1646: 1647: 1648: 1649: 1650: 1651: 1652: 1653: 1654: 1655: 1656:
1657: public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
1658: {
1659: if (isset($alreadyDumpedObjects['Order'][$this->getPrimaryKey()])) {
1660: return '*RECURSION*';
1661: }
1662: $alreadyDumpedObjects['Order'][$this->getPrimaryKey()] = true;
1663: $keys = OrderPeer::getFieldNames($keyType);
1664: $result = array(
1665: $keys[0] => $this->getId(),
1666: $keys[1] => $this->getRef(),
1667: $keys[2] => $this->getCustomerId(),
1668: $keys[3] => $this->getAddressInvoice(),
1669: $keys[4] => $this->getAddressDelivery(),
1670: $keys[5] => $this->getInvoiceDate(),
1671: $keys[6] => $this->getCurrencyId(),
1672: $keys[7] => $this->getCurrencyRate(),
1673: $keys[8] => $this->getTransaction(),
1674: $keys[9] => $this->getDeliveryNum(),
1675: $keys[10] => $this->getInvoice(),
1676: $keys[11] => $this->getPostage(),
1677: $keys[12] => $this->getPayment(),
1678: $keys[13] => $this->getCarrier(),
1679: $keys[14] => $this->getStatusId(),
1680: $keys[15] => $this->getLang(),
1681: $keys[16] => $this->getCreatedAt(),
1682: $keys[17] => $this->getUpdatedAt(),
1683: );
1684: if ($includeForeignObjects) {
1685: if (null !== $this->aCurrency) {
1686: $result['Currency'] = $this->aCurrency->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
1687: }
1688: if (null !== $this->aCustomer) {
1689: $result['Customer'] = $this->aCustomer->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
1690: }
1691: if (null !== $this->aOrderAddressRelatedByAddressInvoice) {
1692: $result['OrderAddressRelatedByAddressInvoice'] = $this->aOrderAddressRelatedByAddressInvoice->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
1693: }
1694: if (null !== $this->aOrderAddressRelatedByAddressDelivery) {
1695: $result['OrderAddressRelatedByAddressDelivery'] = $this->aOrderAddressRelatedByAddressDelivery->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
1696: }
1697: if (null !== $this->aOrderStatus) {
1698: $result['OrderStatus'] = $this->aOrderStatus->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
1699: }
1700: if (null !== $this->collOrderProducts) {
1701: $result['OrderProducts'] = $this->collOrderProducts->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1702: }
1703: if (null !== $this->collCouponOrders) {
1704: $result['CouponOrders'] = $this->collCouponOrders->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
1705: }
1706: }
1707:
1708: return $result;
1709: }
1710:
1711: 1712: 1713: 1714: 1715: 1716: 1717: 1718: 1719: 1720: 1721:
1722: public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
1723: {
1724: $pos = OrderPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
1725:
1726: $this->setByPosition($pos, $value);
1727: }
1728:
1729: 1730: 1731: 1732: 1733: 1734: 1735: 1736:
1737: public function setByPosition($pos, $value)
1738: {
1739: switch ($pos) {
1740: case 0:
1741: $this->setId($value);
1742: break;
1743: case 1:
1744: $this->setRef($value);
1745: break;
1746: case 2:
1747: $this->setCustomerId($value);
1748: break;
1749: case 3:
1750: $this->setAddressInvoice($value);
1751: break;
1752: case 4:
1753: $this->setAddressDelivery($value);
1754: break;
1755: case 5:
1756: $this->setInvoiceDate($value);
1757: break;
1758: case 6:
1759: $this->setCurrencyId($value);
1760: break;
1761: case 7:
1762: $this->setCurrencyRate($value);
1763: break;
1764: case 8:
1765: $this->setTransaction($value);
1766: break;
1767: case 9:
1768: $this->setDeliveryNum($value);
1769: break;
1770: case 10:
1771: $this->setInvoice($value);
1772: break;
1773: case 11:
1774: $this->setPostage($value);
1775: break;
1776: case 12:
1777: $this->setPayment($value);
1778: break;
1779: case 13:
1780: $this->setCarrier($value);
1781: break;
1782: case 14:
1783: $this->setStatusId($value);
1784: break;
1785: case 15:
1786: $this->setLang($value);
1787: break;
1788: case 16:
1789: $this->setCreatedAt($value);
1790: break;
1791: case 17:
1792: $this->setUpdatedAt($value);
1793: break;
1794: }
1795: }
1796:
1797: 1798: 1799: 1800: 1801: 1802: 1803: 1804: 1805: 1806: 1807: 1808: 1809: 1810: 1811: 1812: 1813:
1814: public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
1815: {
1816: $keys = OrderPeer::getFieldNames($keyType);
1817:
1818: if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
1819: if (array_key_exists($keys[1], $arr)) $this->setRef($arr[$keys[1]]);
1820: if (array_key_exists($keys[2], $arr)) $this->setCustomerId($arr[$keys[2]]);
1821: if (array_key_exists($keys[3], $arr)) $this->setAddressInvoice($arr[$keys[3]]);
1822: if (array_key_exists($keys[4], $arr)) $this->setAddressDelivery($arr[$keys[4]]);
1823: if (array_key_exists($keys[5], $arr)) $this->setInvoiceDate($arr[$keys[5]]);
1824: if (array_key_exists($keys[6], $arr)) $this->setCurrencyId($arr[$keys[6]]);
1825: if (array_key_exists($keys[7], $arr)) $this->setCurrencyRate($arr[$keys[7]]);
1826: if (array_key_exists($keys[8], $arr)) $this->setTransaction($arr[$keys[8]]);
1827: if (array_key_exists($keys[9], $arr)) $this->setDeliveryNum($arr[$keys[9]]);
1828: if (array_key_exists($keys[10], $arr)) $this->setInvoice($arr[$keys[10]]);
1829: if (array_key_exists($keys[11], $arr)) $this->setPostage($arr[$keys[11]]);
1830: if (array_key_exists($keys[12], $arr)) $this->setPayment($arr[$keys[12]]);
1831: if (array_key_exists($keys[13], $arr)) $this->setCarrier($arr[$keys[13]]);
1832: if (array_key_exists($keys[14], $arr)) $this->setStatusId($arr[$keys[14]]);
1833: if (array_key_exists($keys[15], $arr)) $this->setLang($arr[$keys[15]]);
1834: if (array_key_exists($keys[16], $arr)) $this->setCreatedAt($arr[$keys[16]]);
1835: if (array_key_exists($keys[17], $arr)) $this->setUpdatedAt($arr[$keys[17]]);
1836: }
1837:
1838: 1839: 1840: 1841: 1842:
1843: public function buildCriteria()
1844: {
1845: $criteria = new Criteria(OrderPeer::DATABASE_NAME);
1846:
1847: if ($this->isColumnModified(OrderPeer::ID)) $criteria->add(OrderPeer::ID, $this->id);
1848: if ($this->isColumnModified(OrderPeer::REF)) $criteria->add(OrderPeer::REF, $this->ref);
1849: if ($this->isColumnModified(OrderPeer::CUSTOMER_ID)) $criteria->add(OrderPeer::CUSTOMER_ID, $this->customer_id);
1850: if ($this->isColumnModified(OrderPeer::ADDRESS_INVOICE)) $criteria->add(OrderPeer::ADDRESS_INVOICE, $this->address_invoice);
1851: if ($this->isColumnModified(OrderPeer::ADDRESS_DELIVERY)) $criteria->add(OrderPeer::ADDRESS_DELIVERY, $this->address_delivery);
1852: if ($this->isColumnModified(OrderPeer::INVOICE_DATE)) $criteria->add(OrderPeer::INVOICE_DATE, $this->invoice_date);
1853: if ($this->isColumnModified(OrderPeer::CURRENCY_ID)) $criteria->add(OrderPeer::CURRENCY_ID, $this->currency_id);
1854: if ($this->isColumnModified(OrderPeer::CURRENCY_RATE)) $criteria->add(OrderPeer::CURRENCY_RATE, $this->currency_rate);
1855: if ($this->isColumnModified(OrderPeer::TRANSACTION)) $criteria->add(OrderPeer::TRANSACTION, $this->transaction);
1856: if ($this->isColumnModified(OrderPeer::DELIVERY_NUM)) $criteria->add(OrderPeer::DELIVERY_NUM, $this->delivery_num);
1857: if ($this->isColumnModified(OrderPeer::INVOICE)) $criteria->add(OrderPeer::INVOICE, $this->invoice);
1858: if ($this->isColumnModified(OrderPeer::POSTAGE)) $criteria->add(OrderPeer::POSTAGE, $this->postage);
1859: if ($this->isColumnModified(OrderPeer::PAYMENT)) $criteria->add(OrderPeer::PAYMENT, $this->payment);
1860: if ($this->isColumnModified(OrderPeer::CARRIER)) $criteria->add(OrderPeer::CARRIER, $this->carrier);
1861: if ($this->isColumnModified(OrderPeer::STATUS_ID)) $criteria->add(OrderPeer::STATUS_ID, $this->status_id);
1862: if ($this->isColumnModified(OrderPeer::LANG)) $criteria->add(OrderPeer::LANG, $this->lang);
1863: if ($this->isColumnModified(OrderPeer::CREATED_AT)) $criteria->add(OrderPeer::CREATED_AT, $this->created_at);
1864: if ($this->isColumnModified(OrderPeer::UPDATED_AT)) $criteria->add(OrderPeer::UPDATED_AT, $this->updated_at);
1865:
1866: return $criteria;
1867: }
1868:
1869: 1870: 1871: 1872: 1873: 1874: 1875: 1876:
1877: public function buildPkeyCriteria()
1878: {
1879: $criteria = new Criteria(OrderPeer::DATABASE_NAME);
1880: $criteria->add(OrderPeer::ID, $this->id);
1881:
1882: return $criteria;
1883: }
1884:
1885: 1886: 1887: 1888:
1889: public function getPrimaryKey()
1890: {
1891: return $this->getId();
1892: }
1893:
1894: 1895: 1896: 1897: 1898: 1899:
1900: public function setPrimaryKey($key)
1901: {
1902: $this->setId($key);
1903: }
1904:
1905: 1906: 1907: 1908:
1909: public function isPrimaryKeyNull()
1910: {
1911:
1912: return null === $this->getId();
1913: }
1914:
1915: 1916: 1917: 1918: 1919: 1920: 1921: 1922: 1923: 1924: 1925:
1926: public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1927: {
1928: $copyObj->setRef($this->getRef());
1929: $copyObj->setCustomerId($this->getCustomerId());
1930: $copyObj->setAddressInvoice($this->getAddressInvoice());
1931: $copyObj->setAddressDelivery($this->getAddressDelivery());
1932: $copyObj->setInvoiceDate($this->getInvoiceDate());
1933: $copyObj->setCurrencyId($this->getCurrencyId());
1934: $copyObj->setCurrencyRate($this->getCurrencyRate());
1935: $copyObj->setTransaction($this->getTransaction());
1936: $copyObj->setDeliveryNum($this->getDeliveryNum());
1937: $copyObj->setInvoice($this->getInvoice());
1938: $copyObj->setPostage($this->getPostage());
1939: $copyObj->setPayment($this->getPayment());
1940: $copyObj->setCarrier($this->getCarrier());
1941: $copyObj->setStatusId($this->getStatusId());
1942: $copyObj->setLang($this->getLang());
1943: $copyObj->setCreatedAt($this->getCreatedAt());
1944: $copyObj->setUpdatedAt($this->getUpdatedAt());
1945:
1946: if ($deepCopy && !$this->startCopy) {
1947:
1948:
1949: $copyObj->setNew(false);
1950:
1951: $this->startCopy = true;
1952:
1953: foreach ($this->getOrderProducts() as $relObj) {
1954: if ($relObj !== $this) {
1955: $copyObj->addOrderProduct($relObj->copy($deepCopy));
1956: }
1957: }
1958:
1959: foreach ($this->getCouponOrders() as $relObj) {
1960: if ($relObj !== $this) {
1961: $copyObj->addCouponOrder($relObj->copy($deepCopy));
1962: }
1963: }
1964:
1965:
1966: $this->startCopy = false;
1967: }
1968:
1969: if ($makeNew) {
1970: $copyObj->setNew(true);
1971: $copyObj->setId(NULL);
1972: }
1973: }
1974:
1975: 1976: 1977: 1978: 1979: 1980: 1981: 1982: 1983: 1984: 1985: 1986:
1987: public function copy($deepCopy = false)
1988: {
1989:
1990: $clazz = get_class($this);
1991: $copyObj = new $clazz();
1992: $this->copyInto($copyObj, $deepCopy);
1993:
1994: return $copyObj;
1995: }
1996:
1997: 1998: 1999: 2000: 2001: 2002: 2003: 2004: 2005:
2006: public function getPeer()
2007: {
2008: if (self::$peer === null) {
2009: self::$peer = new OrderPeer();
2010: }
2011:
2012: return self::$peer;
2013: }
2014:
2015: 2016: 2017: 2018: 2019: 2020: 2021:
2022: public function setCurrency(Currency $v = null)
2023: {
2024: if ($v === null) {
2025: $this->setCurrencyId(NULL);
2026: } else {
2027: $this->setCurrencyId($v->getId());
2028: }
2029:
2030: $this->aCurrency = $v;
2031:
2032:
2033:
2034: if ($v !== null) {
2035: $v->addOrder($this);
2036: }
2037:
2038:
2039: return $this;
2040: }
2041:
2042:
2043: 2044: 2045: 2046: 2047: 2048: 2049:
2050: public function getCurrency(PropelPDO $con = null)
2051: {
2052: if ($this->aCurrency === null && ($this->currency_id !== null)) {
2053: $this->aCurrency = CurrencyQuery::create()->findPk($this->currency_id, $con);
2054: 2055: 2056: 2057: 2058: 2059: 2060:
2061: }
2062:
2063: return $this->aCurrency;
2064: }
2065:
2066: 2067: 2068: 2069: 2070: 2071: 2072:
2073: public function setCustomer(Customer $v = null)
2074: {
2075: if ($v === null) {
2076: $this->setCustomerId(NULL);
2077: } else {
2078: $this->setCustomerId($v->getId());
2079: }
2080:
2081: $this->aCustomer = $v;
2082:
2083:
2084:
2085: if ($v !== null) {
2086: $v->addOrder($this);
2087: }
2088:
2089:
2090: return $this;
2091: }
2092:
2093:
2094: 2095: 2096: 2097: 2098: 2099: 2100:
2101: public function getCustomer(PropelPDO $con = null)
2102: {
2103: if ($this->aCustomer === null && ($this->customer_id !== null)) {
2104: $this->aCustomer = CustomerQuery::create()->findPk($this->customer_id, $con);
2105: 2106: 2107: 2108: 2109: 2110: 2111:
2112: }
2113:
2114: return $this->aCustomer;
2115: }
2116:
2117: 2118: 2119: 2120: 2121: 2122: 2123:
2124: public function setOrderAddressRelatedByAddressInvoice(OrderAddress $v = null)
2125: {
2126: if ($v === null) {
2127: $this->setAddressInvoice(NULL);
2128: } else {
2129: $this->setAddressInvoice($v->getId());
2130: }
2131:
2132: $this->aOrderAddressRelatedByAddressInvoice = $v;
2133:
2134:
2135:
2136: if ($v !== null) {
2137: $v->addOrderRelatedByAddressInvoice($this);
2138: }
2139:
2140:
2141: return $this;
2142: }
2143:
2144:
2145: 2146: 2147: 2148: 2149: 2150: 2151:
2152: public function getOrderAddressRelatedByAddressInvoice(PropelPDO $con = null)
2153: {
2154: if ($this->aOrderAddressRelatedByAddressInvoice === null && ($this->address_invoice !== null)) {
2155: $this->aOrderAddressRelatedByAddressInvoice = OrderAddressQuery::create()->findPk($this->address_invoice, $con);
2156: 2157: 2158: 2159: 2160: 2161: 2162:
2163: }
2164:
2165: return $this->aOrderAddressRelatedByAddressInvoice;
2166: }
2167:
2168: 2169: 2170: 2171: 2172: 2173: 2174:
2175: public function setOrderAddressRelatedByAddressDelivery(OrderAddress $v = null)
2176: {
2177: if ($v === null) {
2178: $this->setAddressDelivery(NULL);
2179: } else {
2180: $this->setAddressDelivery($v->getId());
2181: }
2182:
2183: $this->aOrderAddressRelatedByAddressDelivery = $v;
2184:
2185:
2186:
2187: if ($v !== null) {
2188: $v->addOrderRelatedByAddressDelivery($this);
2189: }
2190:
2191:
2192: return $this;
2193: }
2194:
2195:
2196: 2197: 2198: 2199: 2200: 2201: 2202:
2203: public function getOrderAddressRelatedByAddressDelivery(PropelPDO $con = null)
2204: {
2205: if ($this->aOrderAddressRelatedByAddressDelivery === null && ($this->address_delivery !== null)) {
2206: $this->aOrderAddressRelatedByAddressDelivery = OrderAddressQuery::create()->findPk($this->address_delivery, $con);
2207: 2208: 2209: 2210: 2211: 2212: 2213:
2214: }
2215:
2216: return $this->aOrderAddressRelatedByAddressDelivery;
2217: }
2218:
2219: 2220: 2221: 2222: 2223: 2224: 2225:
2226: public function setOrderStatus(OrderStatus $v = null)
2227: {
2228: if ($v === null) {
2229: $this->setStatusId(NULL);
2230: } else {
2231: $this->setStatusId($v->getId());
2232: }
2233:
2234: $this->aOrderStatus = $v;
2235:
2236:
2237:
2238: if ($v !== null) {
2239: $v->addOrder($this);
2240: }
2241:
2242:
2243: return $this;
2244: }
2245:
2246:
2247: 2248: 2249: 2250: 2251: 2252: 2253:
2254: public function getOrderStatus(PropelPDO $con = null)
2255: {
2256: if ($this->aOrderStatus === null && ($this->status_id !== null)) {
2257: $this->aOrderStatus = OrderStatusQuery::create()->findPk($this->status_id, $con);
2258: 2259: 2260: 2261: 2262: 2263: 2264:
2265: }
2266:
2267: return $this->aOrderStatus;
2268: }
2269:
2270:
2271: 2272: 2273: 2274: 2275: 2276: 2277: 2278:
2279: public function initRelation($relationName)
2280: {
2281: if ('OrderProduct' == $relationName) {
2282: $this->initOrderProducts();
2283: }
2284: if ('CouponOrder' == $relationName) {
2285: $this->initCouponOrders();
2286: }
2287: }
2288:
2289: 2290: 2291: 2292: 2293: 2294: 2295: 2296: 2297:
2298: public function clearOrderProducts()
2299: {
2300: $this->collOrderProducts = null;
2301: $this->collOrderProductsPartial = null;
2302: }
2303:
2304: 2305: 2306: 2307: 2308:
2309: public function resetPartialOrderProducts($v = true)
2310: {
2311: $this->collOrderProductsPartial = $v;
2312: }
2313:
2314: 2315: 2316: 2317: 2318: 2319: 2320: 2321: 2322: 2323: 2324: 2325:
2326: public function initOrderProducts($overrideExisting = true)
2327: {
2328: if (null !== $this->collOrderProducts && !$overrideExisting) {
2329: return;
2330: }
2331: $this->collOrderProducts = new PropelObjectCollection();
2332: $this->collOrderProducts->setModel('OrderProduct');
2333: }
2334:
2335: 2336: 2337: 2338: 2339: 2340: 2341: 2342: 2343: 2344: 2345: 2346: 2347: 2348:
2349: public function getOrderProducts($criteria = null, PropelPDO $con = null)
2350: {
2351: $partial = $this->collOrderProductsPartial && !$this->isNew();
2352: if (null === $this->collOrderProducts || null !== $criteria || $partial) {
2353: if ($this->isNew() && null === $this->collOrderProducts) {
2354:
2355: $this->initOrderProducts();
2356: } else {
2357: $collOrderProducts = OrderProductQuery::create(null, $criteria)
2358: ->filterByOrder($this)
2359: ->find($con);
2360: if (null !== $criteria) {
2361: if (false !== $this->collOrderProductsPartial && count($collOrderProducts)) {
2362: $this->initOrderProducts(false);
2363:
2364: foreach($collOrderProducts as $obj) {
2365: if (false == $this->collOrderProducts->contains($obj)) {
2366: $this->collOrderProducts->append($obj);
2367: }
2368: }
2369:
2370: $this->collOrderProductsPartial = true;
2371: }
2372:
2373: return $collOrderProducts;
2374: }
2375:
2376: if($partial && $this->collOrderProducts) {
2377: foreach($this->collOrderProducts as $obj) {
2378: if($obj->isNew()) {
2379: $collOrderProducts[] = $obj;
2380: }
2381: }
2382: }
2383:
2384: $this->collOrderProducts = $collOrderProducts;
2385: $this->collOrderProductsPartial = false;
2386: }
2387: }
2388:
2389: return $this->collOrderProducts;
2390: }
2391:
2392: 2393: 2394: 2395: 2396: 2397: 2398: 2399: 2400:
2401: public function setOrderProducts(PropelCollection $orderProducts, PropelPDO $con = null)
2402: {
2403: $this->orderProductsScheduledForDeletion = $this->getOrderProducts(new Criteria(), $con)->diff($orderProducts);
2404:
2405: foreach ($this->orderProductsScheduledForDeletion as $orderProductRemoved) {
2406: $orderProductRemoved->setOrder(null);
2407: }
2408:
2409: $this->collOrderProducts = null;
2410: foreach ($orderProducts as $orderProduct) {
2411: $this->addOrderProduct($orderProduct);
2412: }
2413:
2414: $this->collOrderProducts = $orderProducts;
2415: $this->collOrderProductsPartial = false;
2416: }
2417:
2418: 2419: 2420: 2421: 2422: 2423: 2424: 2425: 2426:
2427: public function countOrderProducts(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
2428: {
2429: $partial = $this->collOrderProductsPartial && !$this->isNew();
2430: if (null === $this->collOrderProducts || null !== $criteria || $partial) {
2431: if ($this->isNew() && null === $this->collOrderProducts) {
2432: return 0;
2433: } else {
2434: if($partial && !$criteria) {
2435: return count($this->getOrderProducts());
2436: }
2437: $query = OrderProductQuery::create(null, $criteria);
2438: if ($distinct) {
2439: $query->distinct();
2440: }
2441:
2442: return $query
2443: ->filterByOrder($this)
2444: ->count($con);
2445: }
2446: } else {
2447: return count($this->collOrderProducts);
2448: }
2449: }
2450:
2451: 2452: 2453: 2454: 2455: 2456: 2457:
2458: public function addOrderProduct(OrderProduct $l)
2459: {
2460: if ($this->collOrderProducts === null) {
2461: $this->initOrderProducts();
2462: $this->collOrderProductsPartial = true;
2463: }
2464: if (!$this->collOrderProducts->contains($l)) {
2465: $this->doAddOrderProduct($l);
2466: }
2467:
2468: return $this;
2469: }
2470:
2471: 2472: 2473:
2474: protected function doAddOrderProduct($orderProduct)
2475: {
2476: $this->collOrderProducts[]= $orderProduct;
2477: $orderProduct->setOrder($this);
2478: }
2479:
2480: 2481: 2482:
2483: public function removeOrderProduct($orderProduct)
2484: {
2485: if ($this->getOrderProducts()->contains($orderProduct)) {
2486: $this->collOrderProducts->remove($this->collOrderProducts->search($orderProduct));
2487: if (null === $this->orderProductsScheduledForDeletion) {
2488: $this->orderProductsScheduledForDeletion = clone $this->collOrderProducts;
2489: $this->orderProductsScheduledForDeletion->clear();
2490: }
2491: $this->orderProductsScheduledForDeletion[]= $orderProduct;
2492: $orderProduct->setOrder(null);
2493: }
2494: }
2495:
2496: 2497: 2498: 2499: 2500: 2501: 2502: 2503: 2504:
2505: public function clearCouponOrders()
2506: {
2507: $this->collCouponOrders = null;
2508: $this->collCouponOrdersPartial = null;
2509: }
2510:
2511: 2512: 2513: 2514: 2515:
2516: public function resetPartialCouponOrders($v = true)
2517: {
2518: $this->collCouponOrdersPartial = $v;
2519: }
2520:
2521: 2522: 2523: 2524: 2525: 2526: 2527: 2528: 2529: 2530: 2531: 2532:
2533: public function initCouponOrders($overrideExisting = true)
2534: {
2535: if (null !== $this->collCouponOrders && !$overrideExisting) {
2536: return;
2537: }
2538: $this->collCouponOrders = new PropelObjectCollection();
2539: $this->collCouponOrders->setModel('CouponOrder');
2540: }
2541:
2542: 2543: 2544: 2545: 2546: 2547: 2548: 2549: 2550: 2551: 2552: 2553: 2554: 2555:
2556: public function getCouponOrders($criteria = null, PropelPDO $con = null)
2557: {
2558: $partial = $this->collCouponOrdersPartial && !$this->isNew();
2559: if (null === $this->collCouponOrders || null !== $criteria || $partial) {
2560: if ($this->isNew() && null === $this->collCouponOrders) {
2561:
2562: $this->initCouponOrders();
2563: } else {
2564: $collCouponOrders = CouponOrderQuery::create(null, $criteria)
2565: ->filterByOrder($this)
2566: ->find($con);
2567: if (null !== $criteria) {
2568: if (false !== $this->collCouponOrdersPartial && count($collCouponOrders)) {
2569: $this->initCouponOrders(false);
2570:
2571: foreach($collCouponOrders as $obj) {
2572: if (false == $this->collCouponOrders->contains($obj)) {
2573: $this->collCouponOrders->append($obj);
2574: }
2575: }
2576:
2577: $this->collCouponOrdersPartial = true;
2578: }
2579:
2580: return $collCouponOrders;
2581: }
2582:
2583: if($partial && $this->collCouponOrders) {
2584: foreach($this->collCouponOrders as $obj) {
2585: if($obj->isNew()) {
2586: $collCouponOrders[] = $obj;
2587: }
2588: }
2589: }
2590:
2591: $this->collCouponOrders = $collCouponOrders;
2592: $this->collCouponOrdersPartial = false;
2593: }
2594: }
2595:
2596: return $this->collCouponOrders;
2597: }
2598:
2599: 2600: 2601: 2602: 2603: 2604: 2605: 2606: 2607:
2608: public function setCouponOrders(PropelCollection $couponOrders, PropelPDO $con = null)
2609: {
2610: $this->couponOrdersScheduledForDeletion = $this->getCouponOrders(new Criteria(), $con)->diff($couponOrders);
2611:
2612: foreach ($this->couponOrdersScheduledForDeletion as $couponOrderRemoved) {
2613: $couponOrderRemoved->setOrder(null);
2614: }
2615:
2616: $this->collCouponOrders = null;
2617: foreach ($couponOrders as $couponOrder) {
2618: $this->addCouponOrder($couponOrder);
2619: }
2620:
2621: $this->collCouponOrders = $couponOrders;
2622: $this->collCouponOrdersPartial = false;
2623: }
2624:
2625: 2626: 2627: 2628: 2629: 2630: 2631: 2632: 2633:
2634: public function countCouponOrders(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
2635: {
2636: $partial = $this->collCouponOrdersPartial && !$this->isNew();
2637: if (null === $this->collCouponOrders || null !== $criteria || $partial) {
2638: if ($this->isNew() && null === $this->collCouponOrders) {
2639: return 0;
2640: } else {
2641: if($partial && !$criteria) {
2642: return count($this->getCouponOrders());
2643: }
2644: $query = CouponOrderQuery::create(null, $criteria);
2645: if ($distinct) {
2646: $query->distinct();
2647: }
2648:
2649: return $query
2650: ->filterByOrder($this)
2651: ->count($con);
2652: }
2653: } else {
2654: return count($this->collCouponOrders);
2655: }
2656: }
2657:
2658: 2659: 2660: 2661: 2662: 2663: 2664:
2665: public function addCouponOrder(CouponOrder $l)
2666: {
2667: if ($this->collCouponOrders === null) {
2668: $this->initCouponOrders();
2669: $this->collCouponOrdersPartial = true;
2670: }
2671: if (!$this->collCouponOrders->contains($l)) {
2672: $this->doAddCouponOrder($l);
2673: }
2674:
2675: return $this;
2676: }
2677:
2678: 2679: 2680:
2681: protected function doAddCouponOrder($couponOrder)
2682: {
2683: $this->collCouponOrders[]= $couponOrder;
2684: $couponOrder->setOrder($this);
2685: }
2686:
2687: 2688: 2689:
2690: public function removeCouponOrder($couponOrder)
2691: {
2692: if ($this->getCouponOrders()->contains($couponOrder)) {
2693: $this->collCouponOrders->remove($this->collCouponOrders->search($couponOrder));
2694: if (null === $this->couponOrdersScheduledForDeletion) {
2695: $this->couponOrdersScheduledForDeletion = clone $this->collCouponOrders;
2696: $this->couponOrdersScheduledForDeletion->clear();
2697: }
2698: $this->couponOrdersScheduledForDeletion[]= $couponOrder;
2699: $couponOrder->setOrder(null);
2700: }
2701: }
2702:
2703: 2704: 2705:
2706: public function clear()
2707: {
2708: $this->id = null;
2709: $this->ref = null;
2710: $this->customer_id = null;
2711: $this->address_invoice = null;
2712: $this->address_delivery = null;
2713: $this->invoice_date = null;
2714: $this->currency_id = null;
2715: $this->currency_rate = null;
2716: $this->transaction = null;
2717: $this->delivery_num = null;
2718: $this->invoice = null;
2719: $this->postage = null;
2720: $this->payment = null;
2721: $this->carrier = null;
2722: $this->status_id = null;
2723: $this->lang = null;
2724: $this->created_at = null;
2725: $this->updated_at = null;
2726: $this->alreadyInSave = false;
2727: $this->alreadyInValidation = false;
2728: $this->clearAllReferences();
2729: $this->resetModified();
2730: $this->setNew(true);
2731: $this->setDeleted(false);
2732: }
2733:
2734: 2735: 2736: 2737: 2738: 2739: 2740: 2741: 2742:
2743: public function clearAllReferences($deep = false)
2744: {
2745: if ($deep) {
2746: if ($this->collOrderProducts) {
2747: foreach ($this->collOrderProducts as $o) {
2748: $o->clearAllReferences($deep);
2749: }
2750: }
2751: if ($this->collCouponOrders) {
2752: foreach ($this->collCouponOrders as $o) {
2753: $o->clearAllReferences($deep);
2754: }
2755: }
2756: }
2757:
2758: if ($this->collOrderProducts instanceof PropelCollection) {
2759: $this->collOrderProducts->clearIterator();
2760: }
2761: $this->collOrderProducts = null;
2762: if ($this->collCouponOrders instanceof PropelCollection) {
2763: $this->collCouponOrders->clearIterator();
2764: }
2765: $this->collCouponOrders = null;
2766: $this->aCurrency = null;
2767: $this->aCustomer = null;
2768: $this->aOrderAddressRelatedByAddressInvoice = null;
2769: $this->aOrderAddressRelatedByAddressDelivery = null;
2770: $this->aOrderStatus = null;
2771: }
2772:
2773: 2774: 2775: 2776: 2777:
2778: public function __toString()
2779: {
2780: return (string) $this->exportTo(OrderPeer::DEFAULT_STRING_FORMAT);
2781: }
2782:
2783: 2784: 2785: 2786: 2787:
2788: public function isAlreadyInSave()
2789: {
2790: return $this->alreadyInSave;
2791: }
2792:
2793:
2794:
2795: 2796: 2797: 2798: 2799:
2800: public function keepUpdateDateUnchanged()
2801: {
2802: $this->modifiedColumns[] = OrderPeer::UPDATED_AT;
2803:
2804: return $this;
2805: }
2806:
2807: }
2808: