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