# File core/lib/Thelia/Model/om/BaseOrder.php | thelia

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